Package: api-insee
`🇫🇷
Français <https://github.com/sne3ks/api_insee/blob/master/README.fr.md>`__Python helper to request Sirene APIAPI Sirene give access to French companies and business database.
Entities are recorded since the creation of this administrative register
in 1973. To use this API you have to create an account onhttps://api.insee.fr/The python libraryapi_inseeis a help to request the API Sirene in
perfect simplicity. You’ll find more information about the API in theofficial
documentationInstallationFrom a terminal :pip installapi-inseeTo request the API you must create a consummer account onapi.insee.fr. Then with your access keys :fromapi_inseeimportApiInseeapi=ApiInsee(key=# consummer key,secret=# secret key)Request samplesFetch data from a siret or sirene numberdata=api.siren('005520135').get()data=api.siret('39860733300059').get()# Request executed:# https://api.insee.fr/entreprises/sirene/V3/siren/005520135# https://api.insee.fr/entreprises/sirene/V3/siret/39860733300059Set parameters to the request:data=api.siren('005520135',date='2018-01-01').get()# Request executed:# https://api.insee.fr/entreprises/sirene/V3/siren/005520135?date=2018-01-01Perform an advanced search on given criteria usingq=parameterdata=api.siren(q='unitePurgeeUniteLegage:True').get()# Request executed:# /?q=unitePurgeeUniteLegage:TrueFilter fields in the responsechamps=['siret','denominationUniteLegale','nomUsageUniteLegale','prenom1UniteLegale',]request=api.siret('39860733300059',champs=champs)# Request executed:# /39860733300059?champs=siret,denominationUniteLegale,nomUsageUniteLegale,prenom1UniteLegaleAdvanced search on criteriaClass inapi_insee.criterialet you construct advanced searchs
easily. All variables available are described in theofficial
documentationYou can combine several criteria in one request.fromapi_insee.criteriaimportFielddata=api.siren(q=(Field('codeCommuneEtablissement',92046),Field('unitePurgeeUniteLegale',True))).get()# Request executed:# /?q=codeCommuneEtablissement:92046 AND unitePurgeeUniteLegale:TrueOr using a dictionnarydata=api.siren(q={'codeCommuneEtablissement':92046,'unitePurgeeUniteLegale':True}).get()# Request executed:# /?q=codeCommuneEtablissement:92046 AND unitePurgeeUniteLegale:TrueUse logical operator|,&,- (not)to specify your
requests.data=api.siren(q=(Field('codeCommuneEtablissement',92046)|Field('unitePurgeeUniteLegale',True))).get()data=api.siren(q=-Field('codeCommuneEtablissement',92046)).get()# Request executed:# /?q=codeCommuneEtablissement:92046 OR unitePurgeeUniteLegale:True# /?q=-codeCommuneEtablissement:92046Special SearchTypeDescriptionExampleField
ExactSearch on an
exact valueFieldExa
ct(‘demo
nination
UniteLeg
ale’,’LE
TIMBRE’)
)Perio
dicSearch on
periodic
fieldPeriodic
(Field(’
activite
Principa
leUniteL
egale’,’
84.23Z’)RangeSearch in a
range of
valuesRange(‘n
omUsageU
niteLega
le’,
‘DUPONT’
,
‘DURANT’
)PaginationThepages()method return an iterator to let you fetch pages from
the api. To specify the number of results per page use thenombreargument. Results are limited by 10000 per pages.fromapi_inseeimportApiInseeapi=ApiInsee(key=# consummer key,secret=# secret key)request=api.siren(q={'categorieEntreprise':'PME'})for(page_index,page_result)inenumerate(request.pages(nombre=1000)):# process here