Access the IBGE Aggregate Data API (SIDRA) from Python
Project description
ibgepy
Access the IBGE Aggregate Data API (SIDRA) from Python.
ibgepy is a pandas-friendly interface to the IBGE aggregate data
API of the
Brazilian Institute of Geography and Statistics (IBGE). Query aggregates,
variables, localities, periods, subjects, surveys and metadata from the
surveys and censuses conducted by IBGE — every fetch returns a
pandas.DataFrame.
This is the Python port of the R package
ibger; the public function
names mirror the R API so knowledge transfers directly between the two.
Installation
pip install ibgepy
Requires Python 3.9+, requests and pandas.
Quick start
import ibgepy
# IPCA in Brazil (aggregate 7060), last 6 periods
df = ibgepy.ibge_variables(7060, localities="BR")
# Specific variables for all states
ibgepy.ibge_variables(1705, variable=[284, 285], localities="N3")
# Specific municipalities (São Paulo, Rio) with a classification
ibgepy.ibge_variables(
aggregate=1712,
variable=214,
periods=-3,
localities={"N6": [3550308, 3304557]},
classification={"226": [4844, 96608]},
)
The value column comes back as strings (IBGE uses special codes such as
-, .., ..., X). Convert it with parse_ibge_value:
df["value"] = ibgepy.parse_ibge_value(df["value"])
Discover what to query
ibgepy.ibge_aggregates(periodicity="P5") # list monthly tables
ibgepy.ibge_metadata(7060) # full metadata for a table
ibgepy.ibge_periods(1705) # available periods
ibgepy.ibge_localities(1437, level="N6") # localities at a level
ibgepy.ibge_subjects("internet") # built-in subject-code lookup
ibge_metadata() returns an IbgeMetadata object whose .variables and
.classifications are DataFrames (the categories column holds a nested
DataFrame per classification).
Survey catalog (Metadata API v2)
ibgepy.ibge_surveys() # institutional survey catalog
ibgepy.ibge_survey_periods("SC") # periods with metadata
ibgepy.ibge_survey_metadata("CD", year=2022)
Coming from SIDRA URLs
Already have a SIDRA API URL (e.g. from the SIDRA Query Builder or the R
sidrar package)? Inspect or run it directly:
url = "https://apisidra.ibge.gov.br/values/t/7060/n1/all/v/63/p/last%2012/c315/7169"
ibgepy.parse_sidra_url(url) # human-readable breakdown + equivalent call
ibgepy.fetch_sidra_url(url) # fetch as a tidy DataFrame
Caching and messages
Metadata and the survey catalog are cached in memory per session. Clear it
with ibgepy.ibge_clear_cache(). Silence the progress/success messages with
ibgepy.set_verbose(False).
Public API
| Function | Purpose |
|---|---|
ibge_variables |
Fetch variable data (main function) |
ibge_aggregates |
List aggregates (tables) |
ibge_metadata |
Full aggregate metadata |
ibge_periods |
Available periods |
ibge_localities |
Localities at given levels |
ibge_subjects |
Built-in subject-code lookup |
ibge_surveys / ibge_survey_periods / ibge_survey_metadata |
Survey catalog (Metadata API v2) |
parse_ibge_value |
Convert IBGE value codes to numeric |
parse_sidra_url / fetch_sidra_url |
Translate/execute SIDRA URLs |
ibge_clear_cache |
Clear the in-memory cache |
set_verbose |
Toggle console messages |
License
MIT — see LICENSE. Developed by the ibgepy authors.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ibgepy-0.1.0.tar.gz.
File metadata
- Download URL: ibgepy-0.1.0.tar.gz
- Upload date:
- Size: 27.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77481cba0f02d76e2818ea5fd48133f4e5823172de3e5858abfae3b4667a0ffe
|
|
| MD5 |
533ec97c5d0186981e8f1033a9b48d12
|
|
| BLAKE2b-256 |
13950d47899573a90382cc5611432dc8f0c2f822572d1877518b589e0d5364ba
|
Provenance
The following attestation bundles were made for ibgepy-0.1.0.tar.gz:
Publisher:
publish.yml on StrategicProjects/ibgepy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ibgepy-0.1.0.tar.gz -
Subject digest:
77481cba0f02d76e2818ea5fd48133f4e5823172de3e5858abfae3b4667a0ffe - Sigstore transparency entry: 1863132529
- Sigstore integration time:
-
Permalink:
StrategicProjects/ibgepy@6cba497ccfc0fc1d43393f1291c5c5fead65d27e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/StrategicProjects
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6cba497ccfc0fc1d43393f1291c5c5fead65d27e -
Trigger Event:
release
-
Statement type:
File details
Details for the file ibgepy-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ibgepy-0.1.0-py3-none-any.whl
- Upload date:
- Size: 28.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0522bbc27a2bb40e38dc4e616bf9a231a2016d9a1cea89aa1cbedccc18dd3fa2
|
|
| MD5 |
514d3914686cafe64116ba6e52056c01
|
|
| BLAKE2b-256 |
9ae5ccbce7d808e5700a7f0175a0c6ae212c66eb70309c7ecded032a89c3763c
|
Provenance
The following attestation bundles were made for ibgepy-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on StrategicProjects/ibgepy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ibgepy-0.1.0-py3-none-any.whl -
Subject digest:
0522bbc27a2bb40e38dc4e616bf9a231a2016d9a1cea89aa1cbedccc18dd3fa2 - Sigstore transparency entry: 1863132656
- Sigstore integration time:
-
Permalink:
StrategicProjects/ibgepy@6cba497ccfc0fc1d43393f1291c5c5fead65d27e -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/StrategicProjects
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@6cba497ccfc0fc1d43393f1291c5c5fead65d27e -
Trigger Event:
release
-
Statement type: