api-insee

raw JSON →
1.6 verified Fri May 01 auth: no python

Python helper to query the Sirene API on api.insee.fr. Current version is 1.6, providing access to the Sirene database (companies and establishments) and links of succession. Release cadence is irregular, with recent updates in 2023.

pip install api-insee
error ImportError: No module named 'api_insee'
cause Package not installed or installed under a different name.
fix
Run 'pip install api-insee' and ensure you are using the correct import: 'from api_insee import ApiInsee'.
error TypeError: __init__() missing 2 required positional arguments: 'key' and 'secret'
cause Credentials not provided when creating ApiInsee instance.
fix
Provide both key and secret: api = ApiInsee(key='...', secret='...').
error requests.exceptions.HTTPError: 401 Client Error: Unauthorized
cause Invalid or missing API credentials.
fix
Verify your INSEE API key and secret. Ensure they are correct and have access to the Sirene API.
gotcha The environment variables for credentials are named differently in some examples (INSEE_KEY/INSEE_SECRET vs API_INSEE_KEY/API_INSEE_SECRET). Always use the exact attribute names when passing to the constructor.
fix Use key and secret parameters as shown in the quickstart or set environment variables accordingly.
gotcha The API responses are raw requests.Response objects, not parsed JSON automatically. You must call .json() or .text yourself.
fix Call response.json() after each request to get a Python dict.
gotcha The query parameter 'q' uses the Sirene API's internal syntax (colon-separated field:value). New users often pass plain strings without the proper field prefix.
fix Use the Criteria.Field helper or write queries like 'siren:398607333'.