Skip to main content

A light weight Python library for INE API json-stat

Project description

INEware

INEware is a lightweight Python library that works as a middleware between the client and the API json-stat that INE (Instituto Nacional de Estadística) offers to its users.

This library is designed to facilitate the handling of data from INE datasets, as well as integrating them into a programmatic environment where we can get the most out of this valuable information.

Installation

pip install ineware

Kick off

The first step to use INEware is creating our DatasetINE object. Simply pass the url of the dataset you want to use as argument and you will have your dataset object ready!

from ineware.dataset_class import DatasetINE

# Initialize a DatasetINE object using its url
my_url = "https://servicios.ine.es/wstempus/jsstat/ES/DATASET/24387"
my_dataset = DatasetINE(my_url)

Show Dataset info

Thanks to INEware library you can get any info you need from INE datasets in a really simple way. Just access the different attributes of the DatasetINE object and use them as you need!

from ineware.dataset_class import DatasetINE
import json

if __name__ == '__main__':
    # Initialize a DatasetINE object using its url
    my_url = "https://servicios.ine.es/wstempus/jsstat/ES/DATASET/24387"
    my_dataset = DatasetINE(my_url)

    # Show dataset info by just printing it!
    print(my_dataset)

    # Show dataset notes
    print("------- Dataset notes --------")
    print(my_dataset.notes)
    print('---------------------------------')

    # Show dataset dimensions or attributes
    print("\n------- Dataset dimensions --------")
    print(my_dataset.dimensions)
    print('---------------------------------')

    # Show dataset dimensions and labels for each one
    # We reformat this dictionary by simply applying some indentation and removing ascii characters
    formatted_dict = json.dumps(my_dataset.dimLabels, indent=4, ensure_ascii=False)
    print("\n------- Dataset dimensions and labels --------")
    print(formatted_dict)
    print("\n----------------------------------------------")

Work with Dataset values

INEware also lets you work with the dataset values as you want. As they are stored as a simple list, where each element is uniquely identified by its labels, the effort to get specific values is reduced by far.

from ineware.dataset_class import DatasetINE

if __name__ == '__main__':
    # Initialize the DatasetINE object using its url
    # This url can be modified with a "date" parameter. In this case year 2020 (since 1st January to 31th December)
    # For more information on how to define urls, visit https://www.ine.es/dyngs/DataLab/manual.html?cid=1259945947375
    my_url = "https://servicios.ine.es/wstempus/jsstat/ES/DATASET/2074?date=20200101:20201231"
    my_dataset = DatasetINE(my_url)

    # Print name of the dataset and unit of measure just to know what we are working with
    print(my_dataset)
    print("------- Dataset notes --------")
    print(my_dataset.notes)
    print('---------------------------------')

    # Suppose we want to get only the number of Almería foreign travelers in each month of 2020
    # As method get_value() returns a list, we can iterate over each value in a simple way to show them
    print("\n------- Almería foreign travelers 2020 --------")
    for item in my_dataset.get_value(Provincia="Almería", ViajerosPernoctaciones="Viajero",
                                     Residencia="Residentes en el Extranjero"):
        print(item)
    print("-------------------------------------------------")

Looking for more examples?

Get the source code in my bitbucket repo. There are more examples at /examples directory

Links

You can get more info about how INE API works, URLs Definitions or how to get table identifiers...

All of this an more in the INE official page

License

MIT License

Copyright (c) 2022 Roberto Gamero

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

ineware-0.0.1.tar.gz (6.4 kB view details)

Uploaded Source

Built Distribution

ineware-0.0.1-py3-none-any.whl (6.8 kB view details)

Uploaded Python 3

File details

Details for the file ineware-0.0.1.tar.gz.

File metadata

  • Download URL: ineware-0.0.1.tar.gz
  • Upload date:
  • Size: 6.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for ineware-0.0.1.tar.gz
Algorithm Hash digest
SHA256 bf318aad35244105c99455a71f5ca8fae51b7920132cd43e0c24c3ad8e3c132c
MD5 5c935b0b123b5e9cb18f4ac453118b30
BLAKE2b-256 fc80a9520336557f4ec52c1a26800363a0680dfb908a11cdc3ca1cea36890bae

See more details on using hashes here.

File details

Details for the file ineware-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: ineware-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 6.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.10

File hashes

Hashes for ineware-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 f639b89fde4f4cbdf2ecf4d65a12ed3a202475e8b1a8b3a798a47a13d6b6d5eb
MD5 93d53747083dec9201f130aa64e7417c
BLAKE2b-256 e0e00b7274c61f1c892809bf9cf70bc6d2c4c7e0b328582fef91c58b1a7193cd

See more details on using hashes here.

Supported by

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