bacendata 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Felipe
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,210 @@
1
+ Metadata-Version: 2.4
2
+ Name: bacendata
3
+ Version: 0.1.0
4
+ Summary: Acesso simplificado aos dados do Banco Central do Brasil
5
+ Author: Felipe
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/fmaignacio/bacendata
8
+ Project-URL: Repository, https://github.com/fmaignacio/bacendata
9
+ Project-URL: Issues, https://github.com/fmaignacio/bacendata/issues
10
+ Keywords: bacen,bcb,sgs,banco-central,economia,brasil
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Intended Audience :: Developers
13
+ Classifier: Intended Audience :: Financial and Insurance Industry
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Programming Language :: Python :: 3
16
+ Classifier: Programming Language :: Python :: 3.9
17
+ Classifier: Programming Language :: Python :: 3.10
18
+ Classifier: Programming Language :: Python :: 3.11
19
+ Classifier: Programming Language :: Python :: 3.12
20
+ Classifier: Topic :: Office/Business :: Financial
21
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
22
+ Requires-Python: >=3.9
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: httpx>=0.25.0
26
+ Requires-Dist: pandas>=1.5.0
27
+ Provides-Extra: dev
28
+ Requires-Dist: pytest>=7.0; extra == "dev"
29
+ Requires-Dist: pytest-asyncio>=0.21; extra == "dev"
30
+ Requires-Dist: pytest-cov>=4.0; extra == "dev"
31
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
32
+ Requires-Dist: black>=23.0; extra == "dev"
33
+ Requires-Dist: respx>=0.20; extra == "dev"
34
+ Dynamic: license-file
35
+
36
+ # BacenData
37
+
38
+ Acesso simplificado aos dados do Banco Central do Brasil.
39
+
40
+ Resolve automaticamente a limitacao de 10 anos por consulta imposta pelo BACEN em marco/2025, com paginacao transparente, retry inteligente e cache local.
41
+
42
+ ## Instalacao
43
+
44
+ ```bash
45
+ pip install bacendata
46
+ ```
47
+
48
+ ## Uso rapido
49
+
50
+ ```python
51
+ from bacendata import sgs
52
+
53
+ # Buscar a taxa Selic (por codigo ou nome)
54
+ selic = sgs.get(11, start="2020-01-01")
55
+ selic = sgs.get("selic", start="2020-01-01")
56
+
57
+ # Buscar multiplas series de uma vez
58
+ df = sgs.get({"Selic": 11, "IPCA": 433, "Dolar": 1}, start="2010-01-01")
59
+
60
+ # Ultimos N valores
61
+ ipca = sgs.get(433, last=12)
62
+
63
+ # Buscar mais de 10 anos (paginacao automatica!)
64
+ selic_longa = sgs.get(11, start="2000-01-01", end="2024-12-31")
65
+ ```
66
+
67
+ ## Funcionalidades
68
+
69
+ - **Paginacao automatica** — consultas >10 anos sao divididas em chunks e feitas em paralelo
70
+ - **Multiplas series** — busque varias series de uma vez com `dict`
71
+ - **Catalogo integrado** — use nomes em vez de codigos: `sgs.get("selic")`
72
+ - **Cache local** — evite chamadas repetidas a API do BACEN
73
+ - **Retry com backoff** — trata automaticamente erros 429, 500 e timeouts
74
+ - **Formato flexivel** — aceita datas ISO (`2024-01-01`), brasileiro (`01/01/2024`) e objetos `date`
75
+ - **Retorno pandas** — dados prontos para analise como `DataFrame`
76
+ - **Async nativo** — interface sync (`get`) e async (`aget`) para FastAPI
77
+
78
+ ## Catalogo de series
79
+
80
+ Voce pode usar nomes em vez de codigos numericos:
81
+
82
+ ```python
83
+ sgs.get("selic") # Taxa Selic diaria (codigo 11)
84
+ sgs.get("ipca") # IPCA mensal (codigo 433)
85
+ sgs.get("dolar") # Dolar PTAX compra (codigo 1)
86
+ sgs.get("euro") # Euro compra (codigo 10813)
87
+ sgs.get("focus_ipca") # Expectativa IPCA 12m (codigo 27574)
88
+ sgs.get("focus_selic") # Expectativa Selic (codigo 27575)
89
+ sgs.get("inadimplencia_pf") # Inadimplencia PF (codigo 21112)
90
+ ```
91
+
92
+ Para listar todas as series disponiveis:
93
+
94
+ ```python
95
+ from bacendata.wrapper.catalogo import listar
96
+
97
+ for serie in listar():
98
+ print(f"{serie.codigo:>6} | {serie.nome} ({serie.periodicidade})")
99
+ ```
100
+
101
+ ## Cache local
102
+
103
+ Ative o cache para evitar chamadas repetidas:
104
+
105
+ ```python
106
+ from bacendata import sgs
107
+
108
+ sgs.cache.ativar() # Salva em ~/.bacendata/cache.db
109
+
110
+ selic = sgs.get(11, start="2020-01-01") # Primeira vez: busca na API
111
+ selic = sgs.get(11, start="2020-01-01") # Segunda vez: le do cache
112
+
113
+ # Caminho customizado
114
+ sgs.cache.ativar("/tmp/meu_cache.db")
115
+
116
+ # Limpar cache
117
+ sgs.cache.limpar()
118
+
119
+ # Desativar
120
+ sgs.cache.desativar()
121
+ ```
122
+
123
+ TTL padrao por periodicidade:
124
+ - Series diarias: 1 hora
125
+ - Series semanais: 6 horas
126
+ - Series mensais: 24 horas
127
+
128
+ ## Metadados
129
+
130
+ ```python
131
+ info = sgs.metadata(433)
132
+ # {'codigo': 433, 'nome': 'IPCA - Variacao mensal', 'periodicidade': 'Mensal', ...}
133
+ ```
134
+
135
+ ## Interface async
136
+
137
+ Para uso em FastAPI ou outros frameworks async:
138
+
139
+ ```python
140
+ import asyncio
141
+ from bacendata import sgs
142
+
143
+ async def main():
144
+ df = await sgs.aget(11, start="2020-01-01")
145
+ print(df)
146
+
147
+ asyncio.run(main())
148
+ ```
149
+
150
+ ## Series disponiveis no catalogo
151
+
152
+ | Codigo | Nome | Periodicidade | Aliases |
153
+ |--------|------|---------------|---------|
154
+ | 1 | Dolar (compra) | Diaria | `dolar`, `usd`, `ptax`, `cambio` |
155
+ | 11 | Selic diaria | Diaria | `selic`, `selic_diaria` |
156
+ | 12 | Selic acumulada no mes | Mensal | `selic_mensal`, `selic_acumulada` |
157
+ | 433 | IPCA | Mensal | `ipca`, `inflacao` |
158
+ | 4189 | Juros PF | Mensal | `juros_pf`, `taxa_pf` |
159
+ | 4390 | Selic acumulada anualizada | Mensal | `selic_anual`, `selic_anualizada` |
160
+ | 7326 | Reservas Internacionais | Diaria | `reservas` |
161
+ | 10813 | Euro (compra) | Diaria | `euro`, `eur` |
162
+ | 20542 | Saldo Credito Livre | Mensal | `saldo_credito`, `carteira_credito` |
163
+ | 21082 | Inadimplencia PJ | Mensal | `inadimplencia_pj`, `default_pj` |
164
+ | 21112 | Inadimplencia PF | Mensal | `inadimplencia_pf`, `default_pf` |
165
+ | 25434 | Juros Credito Livre | Mensal | `juros_credito`, `credito_livre` |
166
+ | 27574 | Expectativa IPCA 12m | Semanal | `focus_ipca`, `expectativa_ipca` |
167
+ | 27575 | Expectativa Selic | Semanal | `focus_selic`, `expectativa_selic` |
168
+
169
+ Qualquer codigo SGS funciona mesmo fora do catalogo: `sgs.get(99999, last=10)`.
170
+
171
+ ## Tratamento de erros
172
+
173
+ ```python
174
+ from bacendata.wrapper.exceptions import (
175
+ SerieNaoEncontrada,
176
+ BacenAPIError,
177
+ BacenTimeoutError,
178
+ ParametrosInvalidos,
179
+ )
180
+
181
+ try:
182
+ df = sgs.get(99999, start="2024-01-01")
183
+ except SerieNaoEncontrada:
184
+ print("Serie nao existe")
185
+ except BacenTimeoutError:
186
+ print("API do BACEN nao respondeu")
187
+ except BacenAPIError as e:
188
+ print(f"Erro {e.status_code}: {e.mensagem}")
189
+ ```
190
+
191
+ ## Desenvolvimento
192
+
193
+ ```bash
194
+ git clone https://github.com/fmaignacio/bacendata.git
195
+ cd bacendata
196
+ python -m venv .venv
197
+ source .venv/bin/activate # Linux/Mac
198
+ pip install -e ".[dev]"
199
+
200
+ # Testes
201
+ python -m pytest tests/ -v --cov=src/bacendata
202
+
203
+ # Lint
204
+ ruff check src/ tests/
205
+ black src/ tests/
206
+ ```
207
+
208
+ ## Licenca
209
+
210
+ MIT
@@ -0,0 +1,175 @@
1
+ # BacenData
2
+
3
+ Acesso simplificado aos dados do Banco Central do Brasil.
4
+
5
+ Resolve automaticamente a limitacao de 10 anos por consulta imposta pelo BACEN em marco/2025, com paginacao transparente, retry inteligente e cache local.
6
+
7
+ ## Instalacao
8
+
9
+ ```bash
10
+ pip install bacendata
11
+ ```
12
+
13
+ ## Uso rapido
14
+
15
+ ```python
16
+ from bacendata import sgs
17
+
18
+ # Buscar a taxa Selic (por codigo ou nome)
19
+ selic = sgs.get(11, start="2020-01-01")
20
+ selic = sgs.get("selic", start="2020-01-01")
21
+
22
+ # Buscar multiplas series de uma vez
23
+ df = sgs.get({"Selic": 11, "IPCA": 433, "Dolar": 1}, start="2010-01-01")
24
+
25
+ # Ultimos N valores
26
+ ipca = sgs.get(433, last=12)
27
+
28
+ # Buscar mais de 10 anos (paginacao automatica!)
29
+ selic_longa = sgs.get(11, start="2000-01-01", end="2024-12-31")
30
+ ```
31
+
32
+ ## Funcionalidades
33
+
34
+ - **Paginacao automatica** — consultas >10 anos sao divididas em chunks e feitas em paralelo
35
+ - **Multiplas series** — busque varias series de uma vez com `dict`
36
+ - **Catalogo integrado** — use nomes em vez de codigos: `sgs.get("selic")`
37
+ - **Cache local** — evite chamadas repetidas a API do BACEN
38
+ - **Retry com backoff** — trata automaticamente erros 429, 500 e timeouts
39
+ - **Formato flexivel** — aceita datas ISO (`2024-01-01`), brasileiro (`01/01/2024`) e objetos `date`
40
+ - **Retorno pandas** — dados prontos para analise como `DataFrame`
41
+ - **Async nativo** — interface sync (`get`) e async (`aget`) para FastAPI
42
+
43
+ ## Catalogo de series
44
+
45
+ Voce pode usar nomes em vez de codigos numericos:
46
+
47
+ ```python
48
+ sgs.get("selic") # Taxa Selic diaria (codigo 11)
49
+ sgs.get("ipca") # IPCA mensal (codigo 433)
50
+ sgs.get("dolar") # Dolar PTAX compra (codigo 1)
51
+ sgs.get("euro") # Euro compra (codigo 10813)
52
+ sgs.get("focus_ipca") # Expectativa IPCA 12m (codigo 27574)
53
+ sgs.get("focus_selic") # Expectativa Selic (codigo 27575)
54
+ sgs.get("inadimplencia_pf") # Inadimplencia PF (codigo 21112)
55
+ ```
56
+
57
+ Para listar todas as series disponiveis:
58
+
59
+ ```python
60
+ from bacendata.wrapper.catalogo import listar
61
+
62
+ for serie in listar():
63
+ print(f"{serie.codigo:>6} | {serie.nome} ({serie.periodicidade})")
64
+ ```
65
+
66
+ ## Cache local
67
+
68
+ Ative o cache para evitar chamadas repetidas:
69
+
70
+ ```python
71
+ from bacendata import sgs
72
+
73
+ sgs.cache.ativar() # Salva em ~/.bacendata/cache.db
74
+
75
+ selic = sgs.get(11, start="2020-01-01") # Primeira vez: busca na API
76
+ selic = sgs.get(11, start="2020-01-01") # Segunda vez: le do cache
77
+
78
+ # Caminho customizado
79
+ sgs.cache.ativar("/tmp/meu_cache.db")
80
+
81
+ # Limpar cache
82
+ sgs.cache.limpar()
83
+
84
+ # Desativar
85
+ sgs.cache.desativar()
86
+ ```
87
+
88
+ TTL padrao por periodicidade:
89
+ - Series diarias: 1 hora
90
+ - Series semanais: 6 horas
91
+ - Series mensais: 24 horas
92
+
93
+ ## Metadados
94
+
95
+ ```python
96
+ info = sgs.metadata(433)
97
+ # {'codigo': 433, 'nome': 'IPCA - Variacao mensal', 'periodicidade': 'Mensal', ...}
98
+ ```
99
+
100
+ ## Interface async
101
+
102
+ Para uso em FastAPI ou outros frameworks async:
103
+
104
+ ```python
105
+ import asyncio
106
+ from bacendata import sgs
107
+
108
+ async def main():
109
+ df = await sgs.aget(11, start="2020-01-01")
110
+ print(df)
111
+
112
+ asyncio.run(main())
113
+ ```
114
+
115
+ ## Series disponiveis no catalogo
116
+
117
+ | Codigo | Nome | Periodicidade | Aliases |
118
+ |--------|------|---------------|---------|
119
+ | 1 | Dolar (compra) | Diaria | `dolar`, `usd`, `ptax`, `cambio` |
120
+ | 11 | Selic diaria | Diaria | `selic`, `selic_diaria` |
121
+ | 12 | Selic acumulada no mes | Mensal | `selic_mensal`, `selic_acumulada` |
122
+ | 433 | IPCA | Mensal | `ipca`, `inflacao` |
123
+ | 4189 | Juros PF | Mensal | `juros_pf`, `taxa_pf` |
124
+ | 4390 | Selic acumulada anualizada | Mensal | `selic_anual`, `selic_anualizada` |
125
+ | 7326 | Reservas Internacionais | Diaria | `reservas` |
126
+ | 10813 | Euro (compra) | Diaria | `euro`, `eur` |
127
+ | 20542 | Saldo Credito Livre | Mensal | `saldo_credito`, `carteira_credito` |
128
+ | 21082 | Inadimplencia PJ | Mensal | `inadimplencia_pj`, `default_pj` |
129
+ | 21112 | Inadimplencia PF | Mensal | `inadimplencia_pf`, `default_pf` |
130
+ | 25434 | Juros Credito Livre | Mensal | `juros_credito`, `credito_livre` |
131
+ | 27574 | Expectativa IPCA 12m | Semanal | `focus_ipca`, `expectativa_ipca` |
132
+ | 27575 | Expectativa Selic | Semanal | `focus_selic`, `expectativa_selic` |
133
+
134
+ Qualquer codigo SGS funciona mesmo fora do catalogo: `sgs.get(99999, last=10)`.
135
+
136
+ ## Tratamento de erros
137
+
138
+ ```python
139
+ from bacendata.wrapper.exceptions import (
140
+ SerieNaoEncontrada,
141
+ BacenAPIError,
142
+ BacenTimeoutError,
143
+ ParametrosInvalidos,
144
+ )
145
+
146
+ try:
147
+ df = sgs.get(99999, start="2024-01-01")
148
+ except SerieNaoEncontrada:
149
+ print("Serie nao existe")
150
+ except BacenTimeoutError:
151
+ print("API do BACEN nao respondeu")
152
+ except BacenAPIError as e:
153
+ print(f"Erro {e.status_code}: {e.mensagem}")
154
+ ```
155
+
156
+ ## Desenvolvimento
157
+
158
+ ```bash
159
+ git clone https://github.com/fmaignacio/bacendata.git
160
+ cd bacendata
161
+ python -m venv .venv
162
+ source .venv/bin/activate # Linux/Mac
163
+ pip install -e ".[dev]"
164
+
165
+ # Testes
166
+ python -m pytest tests/ -v --cov=src/bacendata
167
+
168
+ # Lint
169
+ ruff check src/ tests/
170
+ black src/ tests/
171
+ ```
172
+
173
+ ## Licenca
174
+
175
+ MIT
@@ -0,0 +1,65 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "bacendata"
7
+ version = "0.1.0"
8
+ description = "Acesso simplificado aos dados do Banco Central do Brasil"
9
+ readme = "README.md"
10
+ license = {text = "MIT"}
11
+ requires-python = ">=3.9"
12
+ authors = [
13
+ {name = "Felipe"},
14
+ ]
15
+ keywords = ["bacen", "bcb", "sgs", "banco-central", "economia", "brasil"]
16
+ classifiers = [
17
+ "Development Status :: 3 - Alpha",
18
+ "Intended Audience :: Developers",
19
+ "Intended Audience :: Financial and Insurance Industry",
20
+ "License :: OSI Approved :: MIT License",
21
+ "Programming Language :: Python :: 3",
22
+ "Programming Language :: Python :: 3.9",
23
+ "Programming Language :: Python :: 3.10",
24
+ "Programming Language :: Python :: 3.11",
25
+ "Programming Language :: Python :: 3.12",
26
+ "Topic :: Office/Business :: Financial",
27
+ "Topic :: Software Development :: Libraries :: Python Modules",
28
+ ]
29
+ dependencies = [
30
+ "httpx>=0.25.0",
31
+ "pandas>=1.5.0",
32
+ ]
33
+
34
+ [project.urls]
35
+ Homepage = "https://github.com/fmaignacio/bacendata"
36
+ Repository = "https://github.com/fmaignacio/bacendata"
37
+ Issues = "https://github.com/fmaignacio/bacendata/issues"
38
+
39
+ [project.optional-dependencies]
40
+ dev = [
41
+ "pytest>=7.0",
42
+ "pytest-asyncio>=0.21",
43
+ "pytest-cov>=4.0",
44
+ "ruff>=0.1.0",
45
+ "black>=23.0",
46
+ "respx>=0.20",
47
+ ]
48
+
49
+ [tool.setuptools.packages.find]
50
+ where = ["src"]
51
+
52
+ [tool.pytest.ini_options]
53
+ testpaths = ["tests"]
54
+ asyncio_mode = "auto"
55
+
56
+ [tool.ruff]
57
+ target-version = "py39"
58
+ line-length = 100
59
+
60
+ [tool.ruff.lint]
61
+ select = ["E", "F", "I", "W"]
62
+
63
+ [tool.black]
64
+ target-version = ["py39"]
65
+ line-length = 100
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,12 @@
1
+ """
2
+ BacenData — Acesso simplificado aos dados do Banco Central do Brasil.
3
+
4
+ Uso rápido:
5
+ >>> from bacendata import sgs
6
+ >>> selic = sgs.get(11, start="2020-01-01")
7
+ """
8
+
9
+ from bacendata.wrapper import bacen_sgs as sgs
10
+
11
+ __version__ = "0.1.0"
12
+ __all__ = ["sgs", "__version__"]
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes