Skip to main content

PyPi version Tests status Coverage status

Documentation Supported python versions Code style: black PyPi stats

pynsee gives a quick access to more than 150 000 macroeconomic series, a dozen datasets of local data, numerous sources available on insee.fr, geographical limits of administrative areas taken from IGN as well as key metadata and SIRENE database containing data on all French companies. Have a look at the detailed API page portail-api.insee.fr.

This package is a contribution to reproducible research and public data transparency. It benefits from the developments made by teams working on APIs at INSEE and IGN.

Installation & API subscription

Credentials are necessary to access SIRENE API available through pynsee by the module sirene. API credentials can be created here : portail-api.insee.fr. All other modules are freely accessible.

# Download Pypi package
pip install pynsee[full]

# Get the development version from GitHub
# git clone https://github.com/InseeFrLab/pynsee.git
# cd pynsee
# pip install .[full]

# Subscribe to portail-api.insee.fr and get your credentials!
# Save your credentials with init_conn function :
from pynsee.utils import init_conn
init_conn(sirene_key="my_sirene_key")

# Beware : any change to the keys should be tested after having cleared the cache
# Please do : from pynsee.utils import clear_all_cache; clear_all_cache()

Data Search and Collection Advice

  • Macroeconomic data : First, use get_dataset_list to search what are your datasets of interest and then get the series list with get_series_list. Alternatively, you can make a keyword-based search with search_macrodata, e.g. search_macrodata('GDP'). Then, get the data with get_dataset or get_series
  • Local data : use first get_local_metadata, then get data with get_local_data
  • Melodi (progressively replacing Local data and Macroeconomic data) : use first get_catalog, then get data with get_dataset or get_series
  • Metadata : e.g. function to get the classification of economic activities (Naf/Nace Rev2) get_activity_list
  • Sirene (French companies database) : use first get_dimension_list, then use search_sirene with dimensions as filtering variables
  • Geodata : get the list of available geographical data with get_geodata_list and then retrieve it with get_geodata
  • Files on insee.fr: get the list of available files on insee.fr with get_file_list and then download it with download_file

For further advice, have a look at the documentation and gallery of the examples.

Example - Population Map

import math

import matplotlib.cm as cm
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

from pynsee.geodata import get_geodata_list, get_geodata


# get geographical data list
geodata_list = get_geodata_list()
# get departments geographical limits
mapcom = get_geodata("ADMINEXPRESS-COG-CARTO.LATEST:commune").to_crs(epsg=3035)

# area calculations depend on crs which fits metropolitan france but not overseas departements
# figures should not be considered as official statistics
mapcom.attrs["area"] = mapcom.area / 10**6
mapcom = mapcom.to_crs(epsg=3857)

mapcom['REF_AREA'] = 'D' + mapcom['code_insee']
mapcom['density'] = mapcom['population'] / mapcom.attrs["area"]

mapcom = mapcom.transform_overseas(departement=['971', '972', '974', '973', '976', 'NR'],
                          factor=[1.5, 1.5, 1.5, 0.35, 1.5, 1.5])

mapcom = mapcom.zoom(
    departement=["75","92", "93", "91", "77", "78", "95", "94"],
    factor=1.5, startAngle = math.pi * (1 - 3.5 * 1/9))

density_ranges = [
    40, 80, 100, 120, 150, 200, 250, 400, 600, 1000, 2000, 5000, 10000, 20000
]

rvals = np.full(len(mapcom), "< 40", dtype=object)

list_ranges = ["< 40"]

for rmin, rmax in zip(density_ranges, density_ranges[1:]):
    range_string = f"[{rmin}, {rmax}["
    list_ranges.append(range_string)

    rvals[(mapcom.density >= rmin) & (mapcom.density < rmax)] = range_string

rvals[mapcom.density.values > density_ranges[-1]] = "> 20 000"

list_ranges.append("> 20 000")

mapcom.loc[:, "range"] = pd.Categorical(rvals, ordered=True, categories=list_ranges)

fig, ax = plt.subplots(1, 1, figsize=(15, 15))
lgd = {'bbox_to_anchor': (1.1, 0.8), 'title': 'density per km2'}
mapcom.plot(column="range", cmap=cm.viridis, legend=True, ax=ax, legend_kwds=lgd)
ax.set_axis_off()
ax.set(title='Distribution of population in France')
plt.show()

fig.savefig('pop_france.svg',
            format='svg', dpi=1200,
            bbox_inches = 'tight',
            pad_inches = 0)

How to avoid proxy issues ?

# Use the proxy_server argument of the init_conn function to change the proxy server address
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")

# Beware : any change to the keys should be tested after having cleared the cache
# Please do : from pynsee.utils import *; clear_all_cache()

# 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"

Support

Feel free to open an issue with any question about this package using the Github repository.

Contributing

All contributions, whatever their forms, are welcome. See CONTRIBUTING.md

Metadata

Release files for pynsee 0.2.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynsee 0.2.6
File Size Uploaded Provenance Actions
pynsee-0.2.6.tar.gz 9.8 MB Without provenance Details for pynsee-0.2.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pynsee 0.2.6
File Interpreter ABI Platform Actions
pynsee-0.2.6-py3-none-any.whl Python 3 none any Details for pynsee-0.2.6-py3-none-any.whl

Total release size: 19.6 MB

Release files / pynsee-0.2.6.tar.gz

Download URL pynsee-0.2.6.tar.gz
Size 9.8 MB
Tags Source
SHA-256 checksum
How to use checksums
c5e434e6c05879d25ac51c5a07a8e85a0c2394d34bfc95adbec34a2db7cc50d8
BLAKE2b-256 checksum
How to use checksums
f06f7ca57b10e586c6f72972ac8583678096b059c541f307bc0a1313164c814f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / pynsee-0.2.6-py3-none-any.whl

Download URL pynsee-0.2.6-py3-none-any.whl
Size 9.8 MB
Tags Python 3
SHA-256 checksum
How to use checksums
2b3b2416dba503a38eeac1f9b49e7492721401504eebbd981dbee945fdc06a08
BLAKE2b-256 checksum
How to use checksums
61bfe45347cbe5e1a8b65b849da993ff64db5060b99d6ce334ce586fca1179dc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for pynsee 0.2.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page