pynsee


Namepynsee JSON
Version 0.2.0 PyPI version JSON
download
home_pageNone
SummaryTools to Easily Search and Download French Data From INSEE and IGN APIs.
upload_time2025-02-14 12:42:41
maintainerNone
docs_urlNone
authorNone
requires_python>=3.9
licenseThe MIT License (MIT) Copyright (c) 2022 INSEE, Institut national de la statistique et des etudes economiques Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
keywords insee ign statistics demography geospatial france gis statistique démographie géospatial sig
VCS
bugtrack_url
requirements pandas geopandas pyarrow tqdm platformdirs unidecode urllib3 shapely requests requests-ratelimiter
Travis-CI No Travis.
coveralls test coverage
            
[![](https://badge.fury.io/py/pynsee.svg)](https://pypi.org/project/pynsee/)
![Tests Status](https://raw.githubusercontent.com/InseeFrLab/pynsee/refs/heads/master/reports/tests-badge.svg)
![Coverage Status](https://raw.githubusercontent.com/InseeFrLab/pynsee/refs/heads/master/reports/coverage-badge.svg)

<!-- [![](https://github.com/InseeFrLab/pynsee/actions/workflows/pkgTests.yml/badge.svg)](https://github.com/InseeFrLab/pynsee/actions)
[![](https://github.com/InseeFrLab/pynsee/actions/workflows/examples.yml/badge.svg)](https://github.com/InseeFrLab/pynsee/actions) -->
<!-- [![](https://codecov.io/gh/InseeFrLab/pynsee/branch/master/graph/badge.svg?token=TO96FMWRHK)](https://codecov.io/gh/InseeFrLab/pynsee?branch=master) -->
[![](https://readthedocs.org/projects/pynsee/badge/?version=latest)](https://pynsee.readthedocs.io/en/latest/?badge=latest)
[![](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue.svg)](https://www.python.org/)
[![](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)
[![](https://img.shields.io/pypi/dm/pynsee)](https://pypistats.org/packages/pynsee)


``pynsee`` gives a quick access to more than 150 000 macroeconomic series,
a dozen datasets of local data, numerous sources available on [insee.fr](https://www.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](https://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](https://portail-api.insee.fr/). All other modules are freely accessible.

```python

# 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.init_conn 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``
* **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](https://pynsee.readthedocs.io/en/latest/examples.html).


## Example - Population Map

<h1 align="center">
<img src="https://raw.githubusercontent.com/InseeFrLab/pynsee/master/docs/_static/popfrance.png">
</h1>

```python
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['insee_dep']
mapcom['density'] = mapcom['population'] / mapcom.attrs["area"]

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

mapcom = mapcom.zoom(
    departement=["75","92", "93", "91", "77", "78", "95", "94"],
    factor=1.5, startAngle = math.pi * (1 - 3 * 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 ?

```python

# Use the proxy_server argument of the init_conn function to change the proxy server address
from pynsee.utils.init_conn 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](https://github.com/InseeFrLab/pynsee/issues).

## Contributing

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "pynsee",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": null,
    "keywords": "INSEE, IGN, statistics, demography, geospatial, France, GIS, statistique, d\u00e9mographie, g\u00e9ospatial, SIG",
    "author": null,
    "author_email": "Hadrien Leclerc <leclerc.hadrien@gmail.com>, Lino Galiana <lino.galiana@insee.fr>, Thomas Grandjean <thomas.grandjean@developpement-durable.gouv.fr>, Tanguy Fardet <tanguy.fardet@ens-lyon.org>",
    "download_url": "https://files.pythonhosted.org/packages/09/54/f07046c1bb2d974b27062030d3e178dba5c1e5f94e8386195a8500fe4eb2/pynsee-0.2.0.tar.gz",
    "platform": null,
    "description": "\n[![](https://badge.fury.io/py/pynsee.svg)](https://pypi.org/project/pynsee/)\n![Tests Status](https://raw.githubusercontent.com/InseeFrLab/pynsee/refs/heads/master/reports/tests-badge.svg)\n![Coverage Status](https://raw.githubusercontent.com/InseeFrLab/pynsee/refs/heads/master/reports/coverage-badge.svg)\n\n<!-- [![](https://github.com/InseeFrLab/pynsee/actions/workflows/pkgTests.yml/badge.svg)](https://github.com/InseeFrLab/pynsee/actions)\n[![](https://github.com/InseeFrLab/pynsee/actions/workflows/examples.yml/badge.svg)](https://github.com/InseeFrLab/pynsee/actions) -->\n<!-- [![](https://codecov.io/gh/InseeFrLab/pynsee/branch/master/graph/badge.svg?token=TO96FMWRHK)](https://codecov.io/gh/InseeFrLab/pynsee?branch=master) -->\n[![](https://readthedocs.org/projects/pynsee/badge/?version=latest)](https://pynsee.readthedocs.io/en/latest/?badge=latest)\n[![](https://img.shields.io/badge/python-3.9%20%7C%203.10%20%7C%203.11%20%7C%203.12-blue.svg)](https://www.python.org/)\n[![](https://img.shields.io/badge/code%20style-black-000000.svg)](https://pypi.org/project/black/)\n[![](https://img.shields.io/pypi/dm/pynsee)](https://pypistats.org/packages/pynsee)\n\n\n``pynsee`` gives a quick access to more than 150 000 macroeconomic series,\na dozen datasets of local data, numerous sources available on [insee.fr](https://www.insee.fr),\ngeographical limits of administrative areas taken from IGN\nas well as key metadata and SIRENE database containing data on all French companies.\nHave a look at the detailed API page [portail-api.insee.fr](https://portail-api.insee.fr/).\n\nThis package is a contribution to reproducible research and public data transparency.\nIt benefits from the developments made by teams working on APIs at INSEE and IGN.\n\n## Installation & API subscription\n\nCredentials are necessary to access SIRENE API available through `pynsee` by the module `sirene`. API credentials can be created here : [portail-api.insee.fr](https://portail-api.insee.fr/). All other modules are freely accessible.\n\n```python\n\n# Download Pypi package\npip install pynsee[full]\n\n# Get the development version from GitHub\n# git clone https://github.com/InseeFrLab/pynsee.git\n# cd pynsee\n# pip install .[full]\n\n# Subscribe to portail-api.insee.fr and get your credentials!\n# Save your credentials with init_conn function :\nfrom pynsee.utils.init_conn import init_conn\ninit_conn(sirene_key=\"my_sirene_key\")\n\n# Beware : any change to the keys should be tested after having cleared the cache\n# Please do : from pynsee.utils import clear_all_cache; clear_all_cache()\n```\n\n##  Data Search and Collection Advice\n\n* **Macroeconomic data** :\n   First, use ``get_dataset_list`` to search what are your datasets of interest and then get the series list with ``get_series_list``.\n   Alternatively, you can make a keyword-based search with ``search_macrodata``, e.g. ``search_macrodata('GDP')``.\n   Then, get the data with ``get_dataset`` or ``get_series``\n* **Local data** : use first ``get_local_metadata``, then get data with ``get_local_data``\n* **Metadata** : e.g. function to get the classification of economic activities (Naf/Nace Rev2) ``get_activity_list``\n* **Sirene (French companies database)** : use first ``get_dimension_list``, then use ``search_sirene`` with dimensions as filtering variables\n* **Geodata** : get the list of available geographical data with ``get_geodata_list`` and then retrieve it with ``get_geodata``\n* **Files on insee.fr**: get the list of available files on insee.fr with ``get_file_list`` and then download it with ``download_file``\n\nFor further advice, have a look at the documentation and gallery of the [examples](https://pynsee.readthedocs.io/en/latest/examples.html).\n\n\n## Example - Population Map\n\n<h1 align=\"center\">\n<img src=\"https://raw.githubusercontent.com/InseeFrLab/pynsee/master/docs/_static/popfrance.png\">\n</h1>\n\n```python\nimport math\n\nimport matplotlib.cm as cm\nimport matplotlib.pyplot as plt\nimport numpy as np\nimport pandas as pd\n\nfrom pynsee.geodata import get_geodata_list, get_geodata\n\n\n# get geographical data list\ngeodata_list = get_geodata_list()\n# get departments geographical limits\nmapcom = get_geodata(\"ADMINEXPRESS-COG-CARTO.LATEST:commune\").to_crs(epsg=3035)\n\n# area calculations depend on crs which fits metropolitan france but not overseas departements\n# figures should not be considered as official statistics\nmapcom.attrs[\"area\"] = mapcom.area / 10**6\nmapcom = mapcom.to_crs(epsg=3857)\n\nmapcom['REF_AREA'] = 'D' + mapcom['insee_dep']\nmapcom['density'] = mapcom['population'] / mapcom.attrs[\"area\"]\n\nmapcom = mapcom.translate(departement=['971', '972', '974', '973', '976'],\n                          factor=[1.5, 1.5, 1.5, 0.35, 1.5])\n\nmapcom = mapcom.zoom(\n    departement=[\"75\",\"92\", \"93\", \"91\", \"77\", \"78\", \"95\", \"94\"],\n    factor=1.5, startAngle = math.pi * (1 - 3 * 1/9))\n\ndensity_ranges = [\n    40, 80, 100, 120, 150, 200, 250, 400, 600, 1000, 2000, 5000, 10000, 20000\n]\n\nrvals = np.full(len(mapcom), \"< 40\", dtype=object)\n\nlist_ranges = [\"< 40\"]\n\nfor rmin, rmax in zip(density_ranges, density_ranges[1:]):\n    range_string = f\"[{rmin}, {rmax}[\"\n    list_ranges.append(range_string)\n\n    rvals[(mapcom.density >= rmin) & (mapcom.density < rmax)] = range_string\n\nrvals[mapcom.density.values > density_ranges[-1]] = \"> 20 000\"\n\nlist_ranges.append(\"> 20 000\")\n\nmapcom.loc[:, \"range\"] = pd.Categorical(rvals, ordered=True, categories=list_ranges)\n\nfig, ax = plt.subplots(1, 1, figsize=(15, 15))\nlgd = {'bbox_to_anchor': (1.1, 0.8), 'title': 'density per km2'}\nmapcom.plot(column=\"range\", cmap=cm.viridis, legend=True, ax=ax, legend_kwds=lgd)\nax.set_axis_off()\nax.set(title='Distribution of population in France')\nplt.show()\n\nfig.savefig('pop_france.svg',\n            format='svg', dpi=1200,\n            bbox_inches = 'tight',\n            pad_inches = 0)\n```\n\n## How to avoid proxy issues ?\n\n```python\n\n# Use the proxy_server argument of the init_conn function to change the proxy server address\nfrom pynsee.utils.init_conn import init_conn\ninit_conn(sirene_key=\"my_sirene_key\",\n          http_proxy=\"http://my_proxy_server:port\",\n          https_proxy=\"http://my_proxy_server:port\")\n\n# Beware : any change to the keys should be tested after having cleared the cache\n# Please do : from pynsee.utils import *; clear_all_cache()\n\n# Alternativety you can use directly environment variables as follows.\n# Beware not to commit your credentials!\nimport os\nos.environ['sirene_key'] = 'my_sirene_key'\nos.environ['http_proxy'] = \"http://my_proxy_server:port\"\nos.environ['https_proxy'] = \"http://my_proxy_server:port\"\n\n```\n\n## Support\n\nFeel free to open an issue with any question about this package using the [Github repository](https://github.com/InseeFrLab/pynsee/issues).\n\n## Contributing\n\nAll contributions, whatever their forms, are welcome. See ``CONTRIBUTING.md``\n",
    "bugtrack_url": null,
    "license": "The MIT License (MIT)\n        \n        Copyright (c) 2022 INSEE, Institut national de la statistique et des etudes economiques\n        \n        Permission is hereby granted, free of charge, to any person obtaining a copy\n        of this software and associated documentation files (the \"Software\"), to deal\n        in the Software without restriction, including without limitation the rights\n        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n        copies of the Software, and to permit persons to whom the Software is\n        furnished to do so, subject to the following conditions:\n        \n        The above copyright notice and this permission notice shall be included in\n        all copies or substantial portions of the Software.\n        \n        THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\n        THE SOFTWARE.\n        ",
    "summary": "Tools to Easily Search and Download French Data From INSEE and IGN APIs.",
    "version": "0.2.0",
    "project_urls": {
        "bug-tracker": "https://github.com/InseeFrLab/pynsee/issues",
        "documentation": "https://pynsee.readthedocs.io",
        "repository": "https://github.com/InseeFrLab/pynsee"
    },
    "split_keywords": [
        "insee",
        " ign",
        " statistics",
        " demography",
        " geospatial",
        " france",
        " gis",
        " statistique",
        " d\u00e9mographie",
        " g\u00e9ospatial",
        " sig"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "52781932cb85fb1893ee3eeb25ca159e08dcfb603ed956e049a3e0245ccbead2",
                "md5": "985bfd020483fb6a27e0e20c586108dd",
                "sha256": "74a9e5a78b29dc01096dd120b3ab7f5fabd61f726dd7bc7e422d36473bf05716"
            },
            "downloads": -1,
            "filename": "pynsee-0.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "985bfd020483fb6a27e0e20c586108dd",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9802110,
            "upload_time": "2025-02-14T12:42:37",
            "upload_time_iso_8601": "2025-02-14T12:42:37.055022Z",
            "url": "https://files.pythonhosted.org/packages/52/78/1932cb85fb1893ee3eeb25ca159e08dcfb603ed956e049a3e0245ccbead2/pynsee-0.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0954f07046c1bb2d974b27062030d3e178dba5c1e5f94e8386195a8500fe4eb2",
                "md5": "3eb61c445062bbc07acab45659213298",
                "sha256": "fc7af5370ecbf7a8ea08f4a247e37a46d91bac5dd7191da627c602fd5661118e"
            },
            "downloads": -1,
            "filename": "pynsee-0.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "3eb61c445062bbc07acab45659213298",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 9769268,
            "upload_time": "2025-02-14T12:42:41",
            "upload_time_iso_8601": "2025-02-14T12:42:41.559746Z",
            "url": "https://files.pythonhosted.org/packages/09/54/f07046c1bb2d974b27062030d3e178dba5c1e5f94e8386195a8500fe4eb2/pynsee-0.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-14 12:42:41",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "InseeFrLab",
    "github_project": "pynsee",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "requirements": [
        {
            "name": "pandas",
            "specs": [
                [
                    ">=",
                    "2.2.0"
                ],
                [
                    "<",
                    "3.0"
                ]
            ]
        },
        {
            "name": "geopandas",
            "specs": [
                [
                    ">=",
                    "1.0"
                ],
                [
                    "<",
                    "2.0"
                ]
            ]
        },
        {
            "name": "pyarrow",
            "specs": [
                [
                    ">=",
                    "17.0"
                ]
            ]
        },
        {
            "name": "tqdm",
            "specs": [
                [
                    ">=",
                    "4.56"
                ]
            ]
        },
        {
            "name": "platformdirs",
            "specs": [
                [
                    ">=",
                    "4"
                ]
            ]
        },
        {
            "name": "unidecode",
            "specs": [
                [
                    ">=",
                    "1.3"
                ]
            ]
        },
        {
            "name": "urllib3",
            "specs": [
                [
                    ">=",
                    "2.2"
                ]
            ]
        },
        {
            "name": "shapely",
            "specs": [
                [
                    ">=",
                    "2"
                ]
            ]
        },
        {
            "name": "requests",
            "specs": [
                [
                    ">=",
                    "2.32"
                ]
            ]
        },
        {
            "name": "requests-ratelimiter",
            "specs": [
                [
                    ">=",
                    "0.7"
                ]
            ]
        }
    ],
    "lcname": "pynsee"
}
        
Elapsed time: 0.57872s