Configuration and utilities
Utility functions
- pynsee.utils.init_conn(sirene_key: str | None = None, http_proxy: str | None = None, https_proxy: str | None = None) None
Save your credentials to connect to INSEE APIs, subscribe to api.insee.fr
- Parameters:
sirene_key (str, optional) – user’s key for sirene API
http_proxy (str, optional) – Proxy server address, e.g. ‘http://my_proxy_server:port’. Defaults to “”.
https_proxy (str, optional) – Proxy server address, e.g. ‘http://my_proxy_server:port’. Defaults to “”.
Notes
Environment variables can be used instead of init_conn function
Examples
>>> from pynsee.utils import init_conn >>> init_conn(sirene_key="my_sirene_key") >>> # >>> # if the user has to use a proxy server use http_proxy and https_proxy arguments as follows: >>> from pynsee.utils import init_conn >>> init_conn(sirene_key="my_sirene_key", >>> http_proxy="http://my_proxy_server:port", >>> https_proxy="http://my_proxy_server:port") >>> # >>> # Alternativety you can use directly environment variables as follows: >>> # Beware not to commit your credentials! >>> import os >>> os.environ['sirene_key'] = 'my_sirene_key' >>> os.environ['http_proxy'] = "http://my_proxy_server:port" >>> os.environ['https_proxy'] = "http://my_proxy_server:port" >>> init_conn()
- pynsee.utils.clear_all_cache()
Clear the cache of all functions
Notes
If the credentials provided fail to get a token from api.insee.fr even after a double check, try to clear the cache as the output of the function retrieving the token is cached even it is an error.
Examples
>>> from pynsee.utils import clear_all_cache >>> clear_all_cache()
Configuring the library’s behavior
pynsee
can also be configured via the following environment variables:
SIRENE_KEY
takes precedence over the one that may be save in the config fileHTTP_PROXY
andHTTPS_PROXY
also override config proxyPYNSEE_SILENT_MODE
silences all logging information about cached files