Python client for the Banco Central do Brasil SGS (Sistema Gerenciador de Series Temporais) API with 115 curated series codes for Brazilian economic and financial time series.
Project description
bcbpy
Python client for the BCB SGS (Sistema Gerenciador de Series Temporais) API from the Banco Central do Brasil.
Fetch Brazilian economic and financial time series as pandas DataFrames with a simple, Pythonic interface. Includes 115 curated series codes covering exchange rates, interest rates, inflation, GDP, employment, and more.
Installation
pip install bcbpy
Or from source:
git clone https://github.com/TeodoroRodrigo/bcbpy.git
cd bcbpy
pip install -r requirements.txt
Requirements
- Python 3.10+
- pandas
- requests
Quick Start
from bcbpy import fetch_series, fetch_last, fetch_multiple, INTEREST_RATES, EXCHANGE_RATES
# Last 10 CDI daily rates
cdi = fetch_last(INTEREST_RATES["CDI_DAILY"], n=10)
print(cdi)
# USD/BRL exchange rate for 2024
usd = fetch_series(EXCHANGE_RATES["USD_SALE_DAILY"], start_date="2024-01-01", end_date="2024-12-31")
print(usd)
# Multiple series merged into one DataFrame
df = fetch_multiple(
{"CDI": INTEREST_RATES["CDI_DAILY"], "SELIC": INTEREST_RATES["SELIC_DAILY"]},
start_date="2024-01-01",
end_date="2024-12-31",
)
print(df.tail())
API Reference
Functions
fetch_series(code, start_date=None, end_date=None)
Fetch a time series by its SGS numeric code. Returns a pandas DataFrame indexed by date.
from bcbpy import fetch_series
# Accepts YYYY-MM-DD or DD/MM/YYYY date formats
ipca = fetch_series(433, start_date="2023-01-01", end_date="2024-12-31")
fetch_last(code, n=10)
Fetch the last N observations of a series.
from bcbpy import fetch_last
selic = fetch_last(11, n=5)
fetch_multiple(codes_dict, start_date=None, end_date=None)
Fetch multiple series and merge them into a single DataFrame, one column per series.
from bcbpy import fetch_multiple
df = fetch_multiple({"CDI": 12, "SELIC": 11, "TR": 226}, start_date="2024-01-01")
list_codes(category=None)
Print all available series codes. Pass a category name to filter.
from bcbpy import list_codes
list_codes() # all 115 codes across 14 categories
list_codes("INTEREST_RATES") # only interest rate codes
search_codes(keyword)
Search codes by keyword (case-insensitive). Returns a dict of matches.
from bcbpy import search_codes
results = search_codes("IPCA") # finds 15 IPCA-related codes
results = search_codes("USD") # finds USD exchange rate codes
Exceptions
| Exception | When |
|---|---|
SGSError |
Base exception for all API errors |
SGSRateLimitError |
API returns HTTP 429 (too many requests) |
SGSEmptyResponseError |
No data returned for the given query |
Error Handling
from bcbpy import fetch_series, SGSRateLimitError, SGSEmptyResponseError
try:
df = fetch_series(433, start_date="2024-01-01")
except SGSRateLimitError:
print("Rate limited — wait and retry")
except SGSEmptyResponseError:
print("No data for this date range")
Available Series Codes
115 curated codes organized in 14 categories:
| Category | Series | Examples |
|---|---|---|
EXCHANGE_RATES |
6 | USD/BRL daily sale/purchase, monthly averages |
INTEREST_RATES |
10 | Selic, CDI, TR, TBF, TJLP |
INFLATION |
17 | IPCA, INPC, IGP-M, IGP-DI, IPC-Fipe |
IPCA_BREAKDOWN |
11 | Tradeable, non-tradeable, durables, services, cores |
IPCA_CATEGORIES |
9 | Food, housing, transport, health, education |
GDP |
13 | GDP current/constant/USD, per capita, quarterly components |
EMPLOYMENT |
7 | Unemployment rate, labor force, income |
INDUSTRIAL_PRODUCTION |
7 | Manufacturing, mining, capital/intermediate/consumer goods |
FINANCIAL_MARKETS |
7 | Gold, Bovespa, IMA-B |
SAVINGS |
2 | Savings rate and return |
CONFIDENCE |
4 | Consumer (ICC) and business (ICEI) confidence |
ECONOMIC_ACTIVITY |
1 | IBC-Br (GDP proxy, seasonally adjusted) |
BASIC_BASKET |
16 | Cost of living by capital city |
EXCHANGE_RATE_INDEX |
5 | Real effective exchange rate (USD, EUR, JPY, ARS) |
Use any code directly by number or via the category dictionaries:
from bcbpy import INFLATION, GDP
# These are equivalent:
fetch_series(433)
fetch_series(INFLATION["IPCA"])
API Limits
- Date range: max 10 years per query (BCB restriction since March 2025)
- Rate limiting: HTTP 429 on excessive requests (no official limit documented)
- Date formats: the client accepts both
YYYY-MM-DDandDD/MM/YYYY
Project Structure
bcbpy/
├── bcbpy/
│ ├── __init__.py # Public API exports
│ ├── client.py # API client functions and exceptions
│ ├── codes.py # 115 curated series codes in 14 categories
│ └── constants.py # Base URLs and API configuration
├── main.py # CLI demo script
├── pyproject.toml # PyPI packaging metadata
├── BCB_API_REFERENCE.md # Full SGS + Olinda API reference guide
└── README.md
Data Source
All data is fetched from the BCB Open Data Portal under the Open Database License (ODbL).
License
MIT (see LICENSE). The BCB data accessed through this client remains under ODbL; users must comply with ODbL when redistributing data.
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 bcbpy-1.2.0.tar.gz.
File metadata
- Download URL: bcbpy-1.2.0.tar.gz
- Upload date:
- Size: 14.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
63ec4b54824866d696eeec125a6598c4ae87897ce2f4100a62733f3ba8150c64
|
|
| MD5 |
439890997b68244384531292c57b139e
|
|
| BLAKE2b-256 |
feef21a4036b003b9ce37af99d37624cbd275930af06f23ffad2d7c71fe0ef6e
|
Provenance
The following attestation bundles were made for bcbpy-1.2.0.tar.gz:
Publisher:
publish.yml on TeodoroRodrigo/bcbpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bcbpy-1.2.0.tar.gz -
Subject digest:
63ec4b54824866d696eeec125a6598c4ae87897ce2f4100a62733f3ba8150c64 - Sigstore transparency entry: 1342713848
- Sigstore integration time:
-
Permalink:
TeodoroRodrigo/bcbpy@e56a62735724c506316c90039268a5f3b781c59e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TeodoroRodrigo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e56a62735724c506316c90039268a5f3b781c59e -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file bcbpy-1.2.0-py3-none-any.whl.
File metadata
- Download URL: bcbpy-1.2.0-py3-none-any.whl
- Upload date:
- Size: 10.5 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 |
c023f93bfe9944bd855a90c6b717e721d3e166cca242097bbbf78b21001ebf7a
|
|
| MD5 |
782d721b12cd13b2f1cc532ce7c77e87
|
|
| BLAKE2b-256 |
03c2bb53ed617dd01b06eb750ac769fcb4f08ec605a6fe02ddff831392541bd6
|
Provenance
The following attestation bundles were made for bcbpy-1.2.0-py3-none-any.whl:
Publisher:
publish.yml on TeodoroRodrigo/bcbpy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
bcbpy-1.2.0-py3-none-any.whl -
Subject digest:
c023f93bfe9944bd855a90c6b717e721d3e166cca242097bbbf78b21001ebf7a - Sigstore transparency entry: 1342713864
- Sigstore integration time:
-
Permalink:
TeodoroRodrigo/bcbpy@e56a62735724c506316c90039268a5f3b781c59e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/TeodoroRodrigo
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@e56a62735724c506316c90039268a5f3b781c59e -
Trigger Event:
workflow_dispatch
-
Statement type: