DataBR Python SDK
Python SDK for DataBR — Brazilian public data API with automatic x402 payments.
Install
pip install databr
Quick Start
from databr import DataBR
client = DataBR(private_key="0x...")
# BCB — Taxa Selic
selic = client.bcb.selic()
print(selic.data) # {"valor": "14.25", ...}
# Empresa por CNPJ
empresa = client.empresas.consultar("33000167000101")
print(empresa.data["razao_social"])
# Compliance check
compliance = client.compliance.verificar("33000167000101")
How It Works
The SDK handles the x402 payment protocol automatically:
- You call
client.bcb.selic() - The API returns HTTP 402 (Payment Required)
- The SDK signs a USDC payment on Base network
- The SDK retries with the payment proof
- You get the data back
You need USDC on Base network in the wallet corresponding to your private key.
API Reference
Low-Level API
# Direct path access
resp = client.get("/v1/bcb/selic")
resp = client.get("/v1/empresas/33000167000101", format="context")
# Query parameters
resp = client.get("/v1/economia/ipca", fields=["valor"], since="2026-01-01")
# POST endpoints
resp = client.post("/v1/carteira/risco", body={"cnpjs": ["33000167000101"]})
Namespaces
| Namespace | Example | Endpoints |
|---|---|---|
bcb |
client.bcb.selic() |
selic, cambio, focus, credito, reservas, taxas_credito, pix |
empresas |
client.empresas.consultar(cnpj) |
consultar, socios, simples, compliance, perfil_completo, setor, due_diligence |
economia |
client.economia.ipca() |
ipca, pib, panorama |
mercado |
client.mercado.acoes("PETR4") |
acoes, fundos, cotas, fatos, indices, competicao |
compliance |
client.compliance.verificar(cnpj) |
verificar, ceis, cnep, cepim |
judicial |
client.judicial.processos(doc) |
processos, stf, stj, litigio |
legislativo |
client.legislativo.deputados() |
deputados, senadores, proposicoes, votacoes |
ambiental |
client.ambiental.desmatamento() |
desmatamento, prodes, embargos, uso_solo, esg, risco |
transparencia |
client.transparencia.licitacoes() |
licitacoes, contratos, servidores, orcamento, tcu, dou |
saude |
client.saude.medicamentos(reg) |
medicamentos, operadoras, estabelecimentos |
energia |
client.energia.tarifas() |
tarifas, geracao, carga, combustiveis |
transporte |
client.transporte.aeronaves() |
aeronaves, transportadores, acidentes |
educacao |
client.educacao.censo_escolar() |
censo_escolar |
emprego |
client.emprego.rais() |
rais, caged, mercado_trabalho |
comercio |
client.comercio.exportacoes() |
exportacoes, importacoes |
Query Parameters
All methods accept these keyword arguments:
| Parameter | Example | Description |
|---|---|---|
format |
format="context" |
LLM-ready text (+$0.002) |
fields |
fields=["valor", "data"] |
Field projection |
since |
since="2026-01-01" |
Filter by date (from) |
until |
until="2026-02-01" |
Filter by date (to) |
limit |
limit=10 |
Pagination limit |
offset |
offset=20 |
Pagination offset |
Response
resp = client.bcb.selic()
resp.source # "bcb_sgs"
resp.data # {"valor": "14.25", ...}
resp.context # None (or LLM text if format="context")
resp.updated_at # datetime(2026, 2, 23, ...)
resp.cached # True
resp.cache_age_seconds # 3600
resp.cost_usdc # "0.003"
resp.raw # full JSON dict
Error Handling
from databr import DataBR, NotFoundError, PaymentError, RateLimitError
client = DataBR(private_key="0x...")
try:
empresa = client.empresas.consultar("00000000000000")
except NotFoundError:
print("CNPJ not found")
except PaymentError:
print("Payment failed — check USDC balance")
except RateLimitError as e:
print(f"Rate limited — retry in {e.retry_after}s")
Networks
| Network | Usage |
|---|---|
mainnet (default) |
Base mainnet — real USDC payments |
testnet |
Base Sepolia — test USDC (free) |
# Testnet for development
client = DataBR(private_key="0x...", network="testnet")
License
MIT
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
databr-0.1.0.tar.gz
(10.0 kB
view details)
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
databr-0.1.0-py3-none-any.whl
(14.0 kB
view details)
File details
Details for the file databr-0.1.0.tar.gz.
File metadata
- Download URL: databr-0.1.0.tar.gz
- Upload date:
- Size: 10.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f28cd7063cd1da0dd21ae83e64f1f8565358f0331012086ce7464676aa854909
|
|
| MD5 |
fd6c00d8b3a2bde068d124b247a0a6a9
|
|
| BLAKE2b-256 |
1555131e7bbd601dc87ca9abfc3e9e2e8fb96c3cb1470989930e7b0803a92e05
|
File details
Details for the file databr-0.1.0-py3-none-any.whl.
File metadata
- Download URL: databr-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b5e73635a02e0159ea2beb9c54c44daff47b4eb1094ef6d5fb25f10d7dbfd38
|
|
| MD5 |
a5e15b87aa69c3c9216505b7e0e0174b
|
|
| BLAKE2b-256 |
031b63041690033217862dcdd3723a52c52285783498bc1b1f215652c6692471
|