LegifranceClient
LegifranceClient is the single entry point for all calls to the Legifrance
API. It wraps:
- the configuration (
ApiConfig); - PISTE OAuth authentication (see
concepts/piste-oauth); - a
requests.Sessionwith timeout management; - the methods
call_api,get,ping.
Build a client
Section titled “Build a client”Two ways:
from pylegifrance import LegifranceClient
# 1. From the environment (LEGIFRANCE_CLIENT_ID / _SECRET in .env)client = LegifranceClient()
# 2. Manually, with an explicit ApiConfigfrom pylegifrance.config import ApiConfig
client = LegifranceClient( ApiConfig(client_id="...", client_secret="..."))Credentials are mandatory; otherwise an error is raised at instantiation.
Lifecycle
Section titled “Lifecycle”with client.session_context(): ... # API callsThe context closes the session cleanly on exit.
Methods
Section titled “Methods”| Method | Role |
|---|---|
call_api(route, data) | POST JSON to route |
get(route) | GET to route |
ping(route="consult/ping") | Check API reachability |
update_api_keys(...) | Change credentials at runtime |
For the full signature, see /en/references/client.
See also
Section titled “See also”ApiConfig— shape of the config passed to the client.Authentication— what happens before every call.Fond Code,Fond Juri,Fond LODA— facades that consume the client.