Skip to main content

Pyistat is a friendly module made to easily allow anyone to use Python to search and get datasets from ISTAT APIs. There are two modules: the search module is used to find datasets and gives all the information needed to build a request URL. The get module is used to get data after helping you properly setup the dimensions (the keys, as called by ISTAT). Full documentation available on GitHub: https://github.com/DertoVampi/pyistat/tree/main

Project description

pyistat

PyIstat: easy ISTAT APIs requests

Documentation for ISTAT APIs is non-existent and this is a shame. After much grief I created a simple module that allows analysts to search and extract data from their APIs without relying on the outdated information that can be found on the Internet.

How does it work?

PyIstat has two modules: search and get.

The search module

With the search module, you can easily request all the dataflows together with their structure. If you are looking for all dataflows, simply use get_dataflows().

import pandas as pd

df = get_dataflows()

With this code, you'll have a DataFrame with every dataflow available on the ISTAT API. However, if you are looking for a specific dataset, you can use the search_dataflows function.

search_term = ["Gross margin", "Energy"]
df = search_dataflows(search_term, mode="fast", lang="en", returned="dataframe")

The DataFrame returned will be populated with all the datasets found with those terms in their name. If you want to see what dimensions (keys) and dimension values are available, you can set mode="deep". This will return an additional column with a human-readable set of keys and key values. You can also set the language to lang="it", or you can choose to obtain a .csv file.

search_term = ["Gross margin", "Energy"]
search_dataflows(search_term, mode="deep", lang="it", returned="csv"

The get module

After finding the datasets you are most interested in, it's time to get that data from ISTAT APIs. First of all, you can check the dimensions and their ordering by using get_dimensions.

dimensions_df = get_dimensions(dataflow_id)

This will return all the dimensions and their meaning in a readable DataFrame (use Spyder or another IDE with a variable explorer to make it even easier to read). The order of the dimensions will also be displayed, in case you want to pass a list with the dimensions. If you do not want to pass a list, you can pass dimensions as arguments of the function.

# Either pass a list with the ordered dimensions...
dimensions = ["Q", "W", "", "", "", ""] # Make sure to leave the unwanted dimensions with "".
pil_df = get_data("163_156_DF_DCCN_SQCQ_3", dimensions, start_period=2020)


# Or use kwargs...
pil_df = get_data("163_156_DF_DCCN_SQCQ_3", end_period=2024, updated_after=2023, freq="Q", correz="W", returned="csv")

# Or simply get the full data available.
pil_df = get_data("163_156_DF_DCCN_SQCQ_3")

There is an additional variable you can pass to the get_data function, which is force_url=True. Normally, the function checks whether the number of dimensions assigned is the same as the dimensions the dataflow requires, and whether the dimension values you provide are consistent with those of the dataflow. However, for unknown reasons, sometimes the number of dimension found in the structure XML is different from what the dataflow actually requires... In this case, if you are confident the URL is correct (maybe try it in the browser first), you can pass force_url=True to skip the controls.

To do

I made this module as I found the lack of documentation from ISTAT regarding their API access incredibly frustrating. I needed a quick way to get the data from their APIs in order to improve my data pipeline. However, this code needs some refining still; as of now, it works, but it can be more efficient.

If it gains traction I'd be more than happy to fix it wherever there is the need of fixing.

To do: a .exe that is system-and language-agnostic. Fix inefficiencies in the code.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyistat-1.0.0.tar.gz (13.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyistat-1.0.0-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file pyistat-1.0.0.tar.gz.

File metadata

  • Download URL: pyistat-1.0.0.tar.gz
  • Upload date:
  • Size: 13.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Windows/11

File hashes

Hashes for pyistat-1.0.0.tar.gz
Algorithm Hash digest
SHA256 3e146875dfcd7767da45c2ca357800074e8d7d3cd9cba5d03d00e809d4f91235
MD5 7bebb96624d788ccf7b521729d4aedca
BLAKE2b-256 4c4485d7df61b7e4204a28f78a7a096a22f1ed4cf8b1e84a715c6f911631375c

See more details on using hashes here.

File details

Details for the file pyistat-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyistat-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.2 CPython/3.12.9 Windows/11

File hashes

Hashes for pyistat-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb747af06d5910ac8a19f3d2dd9f8d61da92e3eee1753fb385257fe20a325dff
MD5 9121f9fbb678e994c35279040880c551
BLAKE2b-256 f46307e1a11ffd5607d7c84ab89bc9e9ddc19dd03f860b855327ca9ca02a16dd

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page