datosgobes is a python library that provides a simple interface to access the open data API of https://datos.gob.es/es/. The package is designed to make it easy for users to retrieve and analyze data from the API.
It is inspired in the R library rOpenSpain/opendataes.
You can install datosgobes using pip:
pip install datosgobes
Once installed, you can start using datosgobes by importing it in your python script:
import datosgobes
First, you need to initialize the manager:
manager = datosgobes.Manager()
Then, you can use the manager to search for datasets:
datasets = manager.search_datasets('sanidad')
You can also retrieve a dataset by its identifier:
dataset = manager.get_dataset('l01080193-resultados-absolutos-de-las-elecciones-al-parlamento-europeo-de-la-ciudad-de-barcelona')
Once you have a dataset, you can retrieve its metadata, title, description...:
print(dataset.title)
print(dataset.description)
Each dataset can contain multiple distributions. They are stored in a list called distributions
:
print(dataset.distributions)
You can retrieve the data from a distribution by its list index:
distribution = dataset.distribution[0]
The distribution is a class that contains information about the data, such as its title, description, format...:
print(distribution.title)
print(distribution.description)
print(distribution.format)
Finally, you can retrieve the data from the distribution:
data = distribution.data
The data is returned as a pandas DataFrame, if the format is recognized, or as a raw string otherwise. You can use it as you wish.
If you want to contribute to the project, you can fork the repository and submit a pull request. Please make sure to follow the coding standards and documentation guidelines.
datosgobes is released under the MIT license.