python-bcb 0.3.6__tar.gz → 0.4.1__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.
Files changed (97) hide show
  1. {python_bcb-0.3.6 → python_bcb-0.4.1}/.claude/settings.local.json +9 -1
  2. python_bcb-0.4.1/.github/workflows/dependency-audit.yml +31 -0
  3. python_bcb-0.4.1/.github/workflows/integration.yml +29 -0
  4. {python_bcb-0.3.6 → python_bcb-0.4.1}/.github/workflows/lint.yml +1 -1
  5. {python_bcb-0.3.6 → python_bcb-0.4.1}/.github/workflows/sphinx.yml +1 -1
  6. {python_bcb-0.3.6 → python_bcb-0.4.1}/.github/workflows/test.yml +1 -1
  7. {python_bcb-0.3.6 → python_bcb-0.4.1}/.gitignore +7 -1
  8. {python_bcb-0.3.6 → python_bcb-0.4.1}/CHANGELOG.md +25 -0
  9. python_bcb-0.3.6/README.md → python_bcb-0.4.1/PKG-INFO +57 -10
  10. python_bcb-0.3.6/PKG-INFO → python_bcb-0.4.1/README.md +44 -22
  11. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/currency.py +368 -210
  12. python_bcb-0.4.1/bcb/http.py +184 -0
  13. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/odata/api.py +116 -31
  14. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/odata/framework.py +304 -68
  15. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/sgs/__init__.py +197 -73
  16. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/sgs/regional_economy.py +68 -44
  17. python_bcb-0.4.1/docs/_static/images/savefig/ifdata_credito_comparativo.png +0 -0
  18. python_bcb-0.4.1/docs/_static/images/savefig/ifdata_credito_evolucao.png +0 -0
  19. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/async.rst +29 -10
  20. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/currency.rst +43 -9
  21. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/expectativas.rst +9 -6
  22. python_bcb-0.4.1/docs/ifdata.rst +361 -0
  23. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/index.rst +7 -0
  24. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/odata.rst +64 -22
  25. python_bcb-0.4.1/docs/project-health-hardening.md +134 -0
  26. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/sgs.rst +43 -2
  27. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/taxajuros.rst +4 -3
  28. {python_bcb-0.3.6 → python_bcb-0.4.1}/examples/async_usage.py +11 -5
  29. {python_bcb-0.3.6 → python_bcb-0.4.1}/examples/currency_exchange.py +3 -4
  30. {python_bcb-0.3.6 → python_bcb-0.4.1}/examples/sgs_time_series.py +3 -2
  31. {python_bcb-0.3.6 → python_bcb-0.4.1}/pyproject.toml +4 -4
  32. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/conftest.py +1 -1
  33. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/integration/test_currency.py +2 -2
  34. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/sgs/test_regional_economy.py +15 -0
  35. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/sgs/test_series.py +52 -3
  36. python_bcb-0.4.1/tests/test_async.py +461 -0
  37. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/test_currency.py +77 -5
  38. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/test_currency_negative.py +147 -3
  39. python_bcb-0.4.1/tests/test_http.py +198 -0
  40. python_bcb-0.4.1/tests/test_odata.py +926 -0
  41. python_bcb-0.4.1/tests/test_request_timeout.py +192 -0
  42. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/test_sgs_negative.py +83 -2
  43. {python_bcb-0.3.6 → python_bcb-0.4.1}/uv.lock +269 -274
  44. python_bcb-0.3.6/bcb/http.py +0 -98
  45. python_bcb-0.3.6/env.local +0 -1
  46. python_bcb-0.3.6/tests/test_async.py +0 -220
  47. python_bcb-0.3.6/tests/test_odata.py +0 -275
  48. {python_bcb-0.3.6 → python_bcb-0.4.1}/.claude/plans/dynamic-bubbling-glade.md +0 -0
  49. {python_bcb-0.3.6 → python_bcb-0.4.1}/.claude/plans/phase2-review.md +0 -0
  50. {python_bcb-0.3.6 → python_bcb-0.4.1}/.claude/plans/phase4-review.md +0 -0
  51. {python_bcb-0.3.6 → python_bcb-0.4.1}/.claude/plans/recursive-sniffing-snowflake.md +0 -0
  52. {python_bcb-0.3.6 → python_bcb-0.4.1}/.claude/plans/text-output.md +0 -0
  53. {python_bcb-0.3.6 → python_bcb-0.4.1}/.claude/settings.json +0 -0
  54. {python_bcb-0.3.6 → python_bcb-0.4.1}/.python-version +0 -0
  55. {python_bcb-0.3.6 → python_bcb-0.4.1}/CLAUDE.md +0 -0
  56. {python_bcb-0.3.6 → python_bcb-0.4.1}/LICENSE +0 -0
  57. {python_bcb-0.3.6 → python_bcb-0.4.1}/QUESTIONS.md +0 -0
  58. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/__init__.py +0 -0
  59. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/exceptions.py +0 -0
  60. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/odata/__init__.py +0 -0
  61. {python_bcb-0.3.6 → python_bcb-0.4.1}/bcb/utils.py +0 -0
  62. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/.claude/settings.local.json +0 -0
  63. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/Makefile +0 -0
  64. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/_static/images/ipca12m-acumulado.png +0 -0
  65. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/_static/images/savefig/currency1.png +0 -0
  66. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/_static/images/savefig/sgs1.png +0 -0
  67. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/_static/images/savefig/taxajuros1.png +0 -0
  68. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/_static/images/selic.png +0 -0
  69. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/api.rst +0 -0
  70. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/conf.py +0 -0
  71. {python_bcb-0.3.6 → python_bcb-0.4.1}/docs/make.bat +0 -0
  72. {python_bcb-0.3.6 → python_bcb-0.4.1}/examples/odata_query.py +0 -0
  73. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/SGS Economia Regional - Inadimpl/303/252ncia.ipynb" +0 -0
  74. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/bcb_Expectativas_da_SELIC_(nova_API).ipynb +0 -0
  75. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/currency PTAX.ipynb +0 -0
  76. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/currency get EUR parity.ipynb +0 -0
  77. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/currency get strong currencies.ipynb +0 -0
  78. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/currency get with side.ipynb +0 -0
  79. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/currency get.ipynb +0 -0
  80. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/dinheiro em circula/303/247/303/243o.ipynb" +0 -0
  81. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/expectativas IPCA anual.ipynb +0 -0
  82. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/odata ODataAPI.ipynb +0 -0
  83. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/odata examples.ipynb +0 -0
  84. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/odata taxas de juros cheque especial.ipynb +0 -0
  85. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/pix.odata +0 -0
  86. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/sgs get series with join.ipynb +0 -0
  87. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/sgs get series with period index.ipynb +0 -0
  88. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/sgs get series.ipynb +0 -0
  89. {python_bcb-0.3.6 → python_bcb-0.4.1}/notebooks/workspace.ipynb +0 -0
  90. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/__init__.py +0 -0
  91. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/integration/__init__.py +0 -0
  92. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/integration/test_expectativas.py +0 -0
  93. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/integration/test_sgs.py +0 -0
  94. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/sgs/__init__.py +0 -0
  95. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/test_exceptions.py +0 -0
  96. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/test_expectativas.py +0 -0
  97. {python_bcb-0.3.6 → python_bcb-0.4.1}/tests/test_utils.py +0 -0
@@ -40,7 +40,15 @@
40
40
  "mcp__github__add_issue_comment",
41
41
  "Bash(git add:*)",
42
42
  "Bash(git commit:*)",
43
- "Bash(uv sync:*)"
43
+ "Bash(uv sync:*)",
44
+ "Bash(wc -l /home/wilson/dev/python/python-bcb/bcb/**/*.py /home/wilson/dev/python/python-bcb/bcb/*.py)",
45
+ "Bash(xargs ls:*)",
46
+ "Bash(grep -n except.*Exception /home/wilson/dev/python/python-bcb/bcb/**/*.py /home/wilson/dev/python/python-bcb/bcb/*.py)",
47
+ "Bash(grep -n 'type: ignore' /home/wilson/dev/python/python-bcb/bcb/**/*.py /home/wilson/dev/python/python-bcb/bcb/*.py)",
48
+ "Bash(grep -n pass /home/wilson/dev/python/python-bcb/bcb/**/*.py /home/wilson/dev/python/python-bcb/bcb/*.py)",
49
+ "Bash(grep:*)",
50
+ "mcp__github__issue_write",
51
+ "mcp__github__get_me"
44
52
  ]
45
53
  }
46
54
  }
@@ -0,0 +1,31 @@
1
+ name: Dependency Audit
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ schedule:
6
+ - cron: "0 10 * * 1"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ audit:
13
+ runs-on: ubuntu-latest
14
+ timeout-minutes: 20
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Install uv
20
+ uses: astral-sh/setup-uv@v5
21
+
22
+ - name: Set up Python 3.12
23
+ run: uv python install 3.12
24
+
25
+ - name: Export locked dependencies
26
+ run: >-
27
+ uv export --frozen --format requirements-txt --all-groups
28
+ --no-emit-project --no-hashes -o requirements-audit.txt
29
+
30
+ - name: Run dependency audit
31
+ run: uvx pip-audit --requirement requirements-audit.txt
@@ -0,0 +1,29 @@
1
+ name: Integration Tests
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ schedule:
6
+ - cron: "0 9 * * 1"
7
+
8
+ permissions:
9
+ contents: read
10
+
11
+ jobs:
12
+ integration:
13
+ runs-on: ubuntu-latest
14
+ timeout-minutes: 30
15
+
16
+ steps:
17
+ - uses: actions/checkout@v4
18
+
19
+ - name: Install uv
20
+ uses: astral-sh/setup-uv@v5
21
+
22
+ - name: Set up Python 3.12
23
+ run: uv python install 3.12
24
+
25
+ - name: Install dependencies
26
+ run: uv sync --frozen --group test
27
+
28
+ - name: Run integration tests
29
+ run: uv run pytest -m integration
@@ -16,7 +16,7 @@ jobs:
16
16
  run: uv python install 3.10
17
17
 
18
18
  - name: Install dependencies
19
- run: uv sync --group dev
19
+ run: uv sync --frozen --group dev
20
20
 
21
21
  - name: Check formatting
22
22
  run: uv run ruff format --check bcb/ tests/
@@ -20,7 +20,7 @@ jobs:
20
20
  run: uv python install 3.10
21
21
 
22
22
  - name: Install dependencies
23
- run: uv sync --group docs
23
+ run: uv sync --frozen --group docs
24
24
 
25
25
  - name: Build docs
26
26
  run: |
@@ -19,7 +19,7 @@ jobs:
19
19
  run: uv python install ${{ matrix.python-version }}
20
20
 
21
21
  - name: Install dependencies
22
- run: uv sync --group test --group dev
22
+ run: uv sync --frozen --group test --group dev
23
23
 
24
24
  - name: Run tests
25
25
  run: uv run pytest --cov=bcb --cov-report=xml -m "not integration"
@@ -12,4 +12,10 @@ coverage.xml
12
12
  build
13
13
  dist
14
14
  *checkpoint.ipynb
15
- docs/_build/
15
+ docs/_build/
16
+
17
+ # Environment files with secrets
18
+ .env
19
+ .env.local
20
+ env.local
21
+ *.env.local
@@ -1,5 +1,30 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.1] - 2026-10-23
4
+
5
+ ### Fixed
6
+ - PTAX date parameters (`dataCotacao`, `dataInicial`, `dataInicialCotacao`, `dataFinalCotacao`) are now sent as `MM-DD-YYYY`. The `M/D/YYYY` format introduced in 0.4.0 made the PTAX service return empty results. (#69)
7
+
8
+ ### Changed
9
+ - Updated vulnerable transitive dependencies in `uv.lock`. (#68)
10
+
11
+ ## [0.4.0] - 2026-06-15
12
+
13
+ ### Added
14
+ - Added `tidy=True` to `sgs.get()`, `sgs.async_get()`, `currency.get()`, and `currency.async_get()` for long-form DataFrame output. SGS tidy output uses `Date`, `series`, and `value`; currency tidy output uses `Date`, `symbol`, `side`, and `value`. The default wide DataFrame output and `output="text"` behavior are unchanged.
15
+ - Added per-call `timeout` support across SGS, currency, and OData APIs, including sync and async paths, so slow calls can override the shared HTTP client timeout without changing global defaults.
16
+ - Added explicit OR composition for OData filters with the `|` operator, including nested combinations with `&`.
17
+ - Added retry handling for transient SGS request failures.
18
+
19
+ ### Changed
20
+ - Improved OData `describe()` output: detailed endpoint information is now shown by default, while `describe(full=False)` keeps the compact endpoint summary.
21
+ - PTAX date parameters now accept ISO date strings, `datetime.date`, `datetime.datetime`, and `pandas.Timestamp`; generalized inputs are converted to the PTAX service format `M/D/YYYY`.
22
+ - Strengthened public API validation, OData literal serialization, HTTP error mapping, currency response parsing, and async currency missing-symbol behavior.
23
+
24
+ ### Fixed
25
+ - Fixed documentation drift around async client shutdown, timeout usage, raw text output, PTAX date parameters, and tidy DataFrame schemas.
26
+ - Fixed brittle currency integration expectations for missing symbols.
27
+
3
28
  ## [0.3.6] - 2026-03-26
4
29
 
5
30
  ### Added
@@ -1,3 +1,16 @@
1
+ Metadata-Version: 2.5
2
+ Name: python-bcb
3
+ Version: 0.4.1
4
+ Summary: Interface Python para APIs de dados abertos do Banco Central do Brasil.
5
+ Author-email: wilsonfreitas <wilson.freitas@gmail.com>
6
+ License-File: LICENSE
7
+ Requires-Python: >=3.10
8
+ Requires-Dist: httpx>=0.24.0
9
+ Requires-Dist: lxml>=4.9.2
10
+ Requires-Dist: pandas>=2.0.0
11
+ Requires-Dist: tenacity>=8.0.0
12
+ Description-Content-Type: text/markdown
13
+
1
14
  # python-bcb
2
15
 
3
16
  **python-bcb** é uma interface em Python estruturada para obter informações
@@ -40,7 +53,7 @@ Implementado no módulo `currency`, realiza webscraping no site do [Conversor de
40
53
  ### OData - APIs Estruturadas
41
54
 
42
55
  O Banco Central disponibiliza diversas informações em APIs que seguem o padrão [OData](https://odata.org). Inclui:
43
- - **PTAX**: Boletins diários de taxas de câmbio com dados institucionalmentedetalhados
56
+ - **PTAX**: Boletins diários de taxas de câmbio com dados institucionalmente detalhados
44
57
  - **Expectativas**: Expectativas de mercado coletadas do Boletim FOCUS
45
58
  - **TaxaJuros**: Diversas taxas de juros (Selic, CDI, Cheque especial, etc.)
46
59
  - **MercadoImobiliario**: Dados de financiamento imobiliário
@@ -60,7 +73,7 @@ Use esta tabela para escolher o módulo certo para seu caso de uso:
60
73
  | Dados de financiamento imobiliário | `bcb.odata` (MercadoImobiliario) | Originações, taxas médias, volumes |
61
74
  | Informações de instituições financeiras | `bcb.odata` (IFDATA) | Dados de balanço, informações regulatórias |
62
75
  | Análise de dados avançada com filtros | `bcb.odata` (qualquer serviço) | API encadeável, filtragem tipo SQL, ordenação, seleção |
63
- | Busca concorrente de dados | Qualquer módulo com `async_get()` | Requisições não-bloqueantes, melhor performance para operações em massa |
76
+ | Busca concorrente de dados | APIs assíncronas (`sgs`, `currency` e OData) | Requisições não-bloqueantes com `async_get()`, `Endpoint.async_get()` e `ODataQuery.async_collect()` |
64
77
 
65
78
  ## Início Rápido
66
79
 
@@ -106,20 +119,46 @@ df = endpoint.query().filter(endpoint.Indicador == "IPCA").limit(100).collect()
106
119
  - Serviços OData: Varia; consulte documentação BCB para endpoints específicos
107
120
 
108
121
  ### P: Posso buscar dados de forma assíncrona?
109
- **R:** Sim! Todos os módulos têm métodos `async_get()` ou similares. Use-os para requisições concorrentes:
122
+ **R:** Sim. SGS e currency oferecem `async_get()`, e os endpoints OData oferecem `async_get()` e `async_collect()`. Feche o cliente assíncrono ao final de aplicações de longa duração:
110
123
  ```python
111
124
  import asyncio
112
- from bcb import sgs
125
+ from bcb import http, sgs
113
126
 
114
127
  async def main():
115
- results = await asyncio.gather(
116
- sgs.async_get(1), # SELIC
117
- sgs.async_get(433), # IPCA
118
- )
128
+ try:
129
+ results = await asyncio.gather(
130
+ sgs.async_get(1), # SELIC
131
+ sgs.async_get(433), # IPCA
132
+ )
133
+ return results
134
+ finally:
135
+ await http.aclose_async_client()
119
136
 
120
137
  asyncio.run(main())
121
138
  ```
122
139
 
140
+ ### P: Como aumento o timeout de uma consulta lenta?
141
+ **R:** Passe ``timeout`` na própria chamada. O valor é local daquela chamada e
142
+ não altera o cliente HTTP compartilhado globalmente:
143
+
144
+ ```python
145
+ from bcb import sgs, currency, Expectativas
146
+
147
+ # SGS
148
+ selic = sgs.get(11, start="1990-01-01", timeout=120)
149
+
150
+ # Currency
151
+ usd = currency.get("USD", start="1980-01-01", end="2026-01-01", timeout=120)
152
+
153
+ # OData
154
+ em = Expectativas(timeout=120)
155
+ ep = em.get_endpoint("ExpectativasMercadoAnuais")
156
+ df = ep.query().limit(1000).collect(timeout=120)
157
+ ```
158
+
159
+ O padrão continua sendo 30 segundos. No SGS, o timeout vale por tentativa HTTP;
160
+ quando houver retry, cada tentativa usa o mesmo valor.
161
+
123
162
  ### P: Como trato erros e dados faltantes?
124
163
  **R:** A biblioteca lança exceções específicas:
125
164
  - `CurrencyNotFoundError`: Símbolo de moeda não encontrado
@@ -162,7 +201,7 @@ logger.setLevel(logging.DEBUG)
162
201
  - Limites de requisições: APIs BCB podem ter limites; implemente backoff se necessário
163
202
  - Cache: Cache de moedas persiste em memória; limpe se atualizações de dados importarem
164
203
  - Pool de conexões: Usa httpx com connection pooling por padrão
165
- - API Assíncrona: Use métodos async para comportamento verdadeiramente não-bloqueante
204
+ - API Assíncrona: use métodos async para comportamento verdadeiramente não-bloqueante e chame `await bcb.http.aclose_async_client()` no encerramento de aplicações assíncronas longas
166
205
 
167
206
  ### P: Como contribuo ou reporto problemas?
168
207
  **R:** Visite o [repositório GitHub](https://github.com/wilsonfreitas/python-bcb) para:
@@ -171,9 +210,17 @@ logger.setLevel(logging.DEBUG)
171
210
  - Enviar pull requests
172
211
  - Ver documentação
173
212
 
213
+ ### P: Como gero a documentação localmente?
214
+ **R:** As dependências de documentação ficam no grupo `docs` do `uv`:
215
+ ```shell
216
+ uv run --group docs sphinx-build -b html docs docs/_build/html
217
+ ```
218
+
219
+ A saída HTML é gerada em `docs/_build/html`. Edite os arquivos fonte em `docs/`; não edite os arquivos gerados em `docs/_build`.
220
+
174
221
  ### P: Onde encontro documentação mais detalhada?
175
222
  **R:**
176
- - [Documentação de API](https://bcb-python.readthedocs.io/)
223
+ - [Documentação de API](https://wilsonfreitas.github.io/python-bcb/)
177
224
  - [Diretório de Exemplos](./examples/)
178
225
  - Docstrings inline: `help(bcb.sgs.get)`, `help(bcb.currency.get)`, etc.
179
226
  - [Portal de Dados Abertos BCB](https://dadosabertos.bcb.gov.br/)
@@ -1,15 +1,3 @@
1
- Metadata-Version: 2.4
2
- Name: python-bcb
3
- Version: 0.3.6
4
- Author-email: wilsonfreitas <wilson.freitas@gmail.com>
5
- License-File: LICENSE
6
- Requires-Python: >=3.10
7
- Requires-Dist: httpx>=0.24.0
8
- Requires-Dist: lxml>=4.9.2
9
- Requires-Dist: pandas>=2.0.0
10
- Requires-Dist: tenacity>=8.0.0
11
- Description-Content-Type: text/markdown
12
-
13
1
  # python-bcb
14
2
 
15
3
  **python-bcb** é uma interface em Python estruturada para obter informações
@@ -52,7 +40,7 @@ Implementado no módulo `currency`, realiza webscraping no site do [Conversor de
52
40
  ### OData - APIs Estruturadas
53
41
 
54
42
  O Banco Central disponibiliza diversas informações em APIs que seguem o padrão [OData](https://odata.org). Inclui:
55
- - **PTAX**: Boletins diários de taxas de câmbio com dados institucionalmentedetalhados
43
+ - **PTAX**: Boletins diários de taxas de câmbio com dados institucionalmente detalhados
56
44
  - **Expectativas**: Expectativas de mercado coletadas do Boletim FOCUS
57
45
  - **TaxaJuros**: Diversas taxas de juros (Selic, CDI, Cheque especial, etc.)
58
46
  - **MercadoImobiliario**: Dados de financiamento imobiliário
@@ -72,7 +60,7 @@ Use esta tabela para escolher o módulo certo para seu caso de uso:
72
60
  | Dados de financiamento imobiliário | `bcb.odata` (MercadoImobiliario) | Originações, taxas médias, volumes |
73
61
  | Informações de instituições financeiras | `bcb.odata` (IFDATA) | Dados de balanço, informações regulatórias |
74
62
  | Análise de dados avançada com filtros | `bcb.odata` (qualquer serviço) | API encadeável, filtragem tipo SQL, ordenação, seleção |
75
- | Busca concorrente de dados | Qualquer módulo com `async_get()` | Requisições não-bloqueantes, melhor performance para operações em massa |
63
+ | Busca concorrente de dados | APIs assíncronas (`sgs`, `currency` e OData) | Requisições não-bloqueantes com `async_get()`, `Endpoint.async_get()` e `ODataQuery.async_collect()` |
76
64
 
77
65
  ## Início Rápido
78
66
 
@@ -118,20 +106,46 @@ df = endpoint.query().filter(endpoint.Indicador == "IPCA").limit(100).collect()
118
106
  - Serviços OData: Varia; consulte documentação BCB para endpoints específicos
119
107
 
120
108
  ### P: Posso buscar dados de forma assíncrona?
121
- **R:** Sim! Todos os módulos têm métodos `async_get()` ou similares. Use-os para requisições concorrentes:
109
+ **R:** Sim. SGS e currency oferecem `async_get()`, e os endpoints OData oferecem `async_get()` e `async_collect()`. Feche o cliente assíncrono ao final de aplicações de longa duração:
122
110
  ```python
123
111
  import asyncio
124
- from bcb import sgs
112
+ from bcb import http, sgs
125
113
 
126
114
  async def main():
127
- results = await asyncio.gather(
128
- sgs.async_get(1), # SELIC
129
- sgs.async_get(433), # IPCA
130
- )
115
+ try:
116
+ results = await asyncio.gather(
117
+ sgs.async_get(1), # SELIC
118
+ sgs.async_get(433), # IPCA
119
+ )
120
+ return results
121
+ finally:
122
+ await http.aclose_async_client()
131
123
 
132
124
  asyncio.run(main())
133
125
  ```
134
126
 
127
+ ### P: Como aumento o timeout de uma consulta lenta?
128
+ **R:** Passe ``timeout`` na própria chamada. O valor é local daquela chamada e
129
+ não altera o cliente HTTP compartilhado globalmente:
130
+
131
+ ```python
132
+ from bcb import sgs, currency, Expectativas
133
+
134
+ # SGS
135
+ selic = sgs.get(11, start="1990-01-01", timeout=120)
136
+
137
+ # Currency
138
+ usd = currency.get("USD", start="1980-01-01", end="2026-01-01", timeout=120)
139
+
140
+ # OData
141
+ em = Expectativas(timeout=120)
142
+ ep = em.get_endpoint("ExpectativasMercadoAnuais")
143
+ df = ep.query().limit(1000).collect(timeout=120)
144
+ ```
145
+
146
+ O padrão continua sendo 30 segundos. No SGS, o timeout vale por tentativa HTTP;
147
+ quando houver retry, cada tentativa usa o mesmo valor.
148
+
135
149
  ### P: Como trato erros e dados faltantes?
136
150
  **R:** A biblioteca lança exceções específicas:
137
151
  - `CurrencyNotFoundError`: Símbolo de moeda não encontrado
@@ -174,7 +188,7 @@ logger.setLevel(logging.DEBUG)
174
188
  - Limites de requisições: APIs BCB podem ter limites; implemente backoff se necessário
175
189
  - Cache: Cache de moedas persiste em memória; limpe se atualizações de dados importarem
176
190
  - Pool de conexões: Usa httpx com connection pooling por padrão
177
- - API Assíncrona: Use métodos async para comportamento verdadeiramente não-bloqueante
191
+ - API Assíncrona: use métodos async para comportamento verdadeiramente não-bloqueante e chame `await bcb.http.aclose_async_client()` no encerramento de aplicações assíncronas longas
178
192
 
179
193
  ### P: Como contribuo ou reporto problemas?
180
194
  **R:** Visite o [repositório GitHub](https://github.com/wilsonfreitas/python-bcb) para:
@@ -183,9 +197,17 @@ logger.setLevel(logging.DEBUG)
183
197
  - Enviar pull requests
184
198
  - Ver documentação
185
199
 
200
+ ### P: Como gero a documentação localmente?
201
+ **R:** As dependências de documentação ficam no grupo `docs` do `uv`:
202
+ ```shell
203
+ uv run --group docs sphinx-build -b html docs docs/_build/html
204
+ ```
205
+
206
+ A saída HTML é gerada em `docs/_build/html`. Edite os arquivos fonte em `docs/`; não edite os arquivos gerados em `docs/_build`.
207
+
186
208
  ### P: Onde encontro documentação mais detalhada?
187
209
  **R:**
188
- - [Documentação de API](https://bcb-python.readthedocs.io/)
210
+ - [Documentação de API](https://wilsonfreitas.github.io/python-bcb/)
189
211
  - [Diretório de Exemplos](./examples/)
190
212
  - Docstrings inline: `help(bcb.sgs.get)`, `help(bcb.currency.get)`, etc.
191
213
  - [Portal de Dados Abertos BCB](https://dadosabertos.bcb.gov.br/)