SGS2
A lightweight Python library for fetching historical economic data from the Brazilian Central Bank's SGS system.
Installation
pip install sgs2
Usage
dataframe()
Fetch time series data as a pandas DataFrame.
import sgs2 as sgs
# Get a single time series as a DataFrame
df = sgs.dataframe(12) # CDI (Brazilian Interbank Deposit Rate)
# Returns a DataFrame with date as index and code as column name
# Get data with a custom date range
df = sgs.dataframe(12, start='2020-01-01', end='2021-01-01')
# Get multiple series at once
df = sgs.dataframe([12, 433, 189])
# Returns a DataFrame with date as index and codes as column names
# Get multiple series with custom column names
df = sgs.dataframe({433: 'ipca', 189: 'igpm', 12: 'cdi'})
# Returns a DataFrame with date as index and custom names as column names
series()
Fetch a single time series as a pandas Series.
import sgs2 as sgs
# Get a single time series as a Series
s = sgs.series(12) # CDI (Brazilian Interbank Deposit Rate)
# Returns a Series with date as index and values as data
# Get data with a custom date range
s = sgs.series(12, start='2020-01-01', end='2021-01-01')
# Get a series with a custom name
s = sgs.series({12: 'cdi'})
# Returns a Series with date as index and 'cdi' as name
json()
Fetch the raw JSON data from the API.
# Get JSON data for a single series
sgs.json(12)
# Get JSON data with a custom date range
sgs.json(12, start='2020-01-01', end='2021-01-01')
# Get JSON data for multiple series as a list
sgs.json([12, 433, 189])
# Get JSON data for multiple series with custom names
sgs.json({12: 'cdi', 433: 'ipca', 189: 'igpm'})
# All parameters work the same as with dataframe()
sgs.json([12, 433], start='2020-01-01', end='2021-01-01')
metadata()
Fetch metadata about a series.
sgs.metadata(12)
Example output:
{
'code': '12',
'name': 'Taxa de juros - CDI',
'unit': '% a.d.',
'frequency': 'D',
'start_date': '06/03/1986',
'end_date': '19/03/2025',
'source_name': 'Cetip',
'special': 'N'
}
search()
Search for series by keyword.
sgs.search('cdi')
Example output:
[
{
'code': '12',
'name': 'Taxa de juros - CDI',
'unit': '% a.d.',
'frequency': 'D',
'start_date': '06/03/1986',
'end_date': '19/03/2025',
'source_name': 'Cetip',
'special': 'N'
},
{
'code': '4389',
'name': 'Taxa de juros - CDI anualizada base 252',
'unit': '% a.a.',
'frequency': 'D',
'start_date': '06/03/1986',
'end_date': '19/03/2025',
'source_name': 'BCB-Demab',
'special': 'N'
},
{
'code': '4391',
'name': 'Taxa de juros - CDI acumulada no mês',
'unit': '% a.m.',
'frequency': 'M',
'start_date': '31/07/1986',
'end_date': 'mar/2025',
'source_name': 'BCB-Demab',
'special': 'N'
},
{
'code': '4392',
'name': 'Taxa de juros - CDI acumulada no mês anualizada base 252',
'unit': '% a.a.',
'frequency': 'M',
'start_date': '31/07/1986',
'end_date': 'mar/2025',
'source_name': 'BCB-Demab',
'special': 'N'
}
]
Data Codes
Some common series codes:
12: CDI (Brazilian Interbank Deposit Rate)433: IPCA189: IGP-M (General Market Price Index)
License
MIT
Metadata
Release files for sgs2 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sgs2-0.1.1.tar.gz | 5.3 kB | Without provenance | Details for sgs2-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sgs2-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for sgs2-0.1.1-py3-none-any.whl |
Total release size: 11.0 kB
Release files / sgs2-0.1.1.tar.gz
| Download URL | sgs2-0.1.1.tar.gz |
|---|---|
| Size | 5.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fa291083b01a0e6b3e3f149066e4eab63e7576dae12bbee290da911f579a93b2
|
|
BLAKE2b-256 checksum How to use checksums |
99b23bce3a83d92d17f9bf33422bb960d3758f151285910a369ea5638924e4f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.13.1 Windows/11
|
Release files / sgs2-0.1.1-py3-none-any.whl
| Download URL | sgs2-0.1.1-py3-none-any.whl |
|---|---|
| Size | 5.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6a3414c6d891aa83ce9606dc08a93fec6781060eadfb1ee046466184a71b488d
|
|
BLAKE2b-256 checksum How to use checksums |
e670bb90ad07eb920d2717638228509df6d630e805a42853af432cd7fef02208
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.1 CPython/3.13.1 Windows/11
|
Security for sgs2 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.