Python library to extract finance market data from brazillian financial institutions: B3, ANBIMA, Tesouro Direto, CVM.
Project description
brasa
Extract finance market data from brazillian financial institutions: B3, ANBIMA, Tesouro Direto, CVM.
Installation
Install from PyPI (published as brasa-marketdata; the import name is still brasa):
pip install brasa-marketdata
Or directly from GitHub (latest main):
pip install git+https://github.com/wilsonfreitas/brasa.git
With uv:
uv add brasa-marketdata
uv add git+https://github.com/wilsonfreitas/brasa.git
Cache location (BRASA_DATA_PATH)
brasa stores everything — raw downloads, parsed parquet, and the metadata DB —
under a single brasa home, resolved from the BRASA_DATA_PATH environment
variable (falling back to ./.brasa-cache).
A common setup keeps one central home exported globally (e.g. in ~/.env.local).
For a one-off, project-local dataset, create a separate home and point at it for
the current shell only — a per-shell export shadows the global value:
BRASA_DATA_PATH=./brasa-home uv run python -m brasa.cli setup
setup then prints the exact line to activate that home:
Brasa home ready at /abs/path/to/brasa-home
To use this home in your shell:
export BRASA_DATA_PATH="/abs/path/to/brasa-home"
Run that export and every brasa command in the session uses the project-local
home; open a new shell to return to the central one.
Changelog
Deterministic Download Status Codes
Every download attempt is now classified with a single, unambiguous status code
persisted in the download_trials table:
| Symbol | Name | Trigger |
|---|---|---|
. |
PASSED | Successful download |
F |
FAILED | Expected failure (DownloadException) |
E |
ERROR | Unexpected exception |
S |
SKIPPED | Skipped (cache hit / invalid / duplicated) |
D |
DUPLICATED | Raw folder already exists |
I |
INVALID | Content validation failure |
W |
WARNING | Success with warnings |
DB migration: Existing caches are upgraded automatically on startup.
Legacy downloaded=1 rows become PASSED; downloaded=0 become FAILED.
A standalone migration script is also available:
uv run python scripts/migrate_download_trials_status.py
See docs/USER_GUIDE.md for full details.
Import Local Files (import_marketdata / brasa import)
Files with no download URL — a one-off vendor file, a manually-provided upload,
or a corrected file for backfill — can now be imported using the same
validate → gzip → checksum-dedup → parse → store engine as download. Only
the acquisition step changes: bytes are read from disk instead of HTTP.
# Backfill a single date into a template that normally downloads via HTTP
brasa import b3-cotahist-daily --path /data/backfill/COTAHIST_D02012024.TXT --arg refdate=2024-01-02
# Bulk import one file per business day using a date pattern
brasa import my-daily-template --path '/data/prices/%Y-%m-%d.csv' --arg refdate=@2026-06-01:2026-06-30
from brasa import import_marketdata
import_marketdata("b3-cotahist-daily", path="/data/backfill/COTAHIST_D02012024.TXT", refdate="2024-01-02")
See docs/CLI.md, docs/API_REFERENCE.md, and docs/TEMPLATES.md for full details.
Publishing to PyPI
brasa is built with hatchling and published manually
under the distribution name brasa-marketdata (the PyPI name brasa was
already taken by an unrelated project; import brasa is unaffected).
Templates and SQL DDL are bundled inside the package (brasa/files/), so the
built wheel is self-contained.
-
Bump
versioninpyproject.toml. -
Build the wheel and sdist:
uv buildDistributions are written to
dist/. -
(Optional) Verify the wheel bundles the data files:
BRASA_BUILD_TEST=1 uv run pytest tests/test_packaging_wheel.py -v
-
(Optional) Smoke-test in a clean environment:
python -m venv /tmp/brasa-smoke /tmp/brasa-smoke/bin/pip install dist/brasa_marketdata-*.whl /tmp/brasa-smoke/bin/python -c "import brasa; from brasa.engine.template import list_templates; print(len(list_templates()))"
-
Publish:
# TestPyPI dry-run first (recommended) uv publish --publish-url https://test.pypi.org/legacy/ --token "$TEST_PYPI_TOKEN" # Production uv publish --token "$UV_PUBLISH_TOKEN"
A PyPI API token can be supplied via
--token, theUV_PUBLISH_TOKENenvironment variable, or~/.pypirc.
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 brasa_marketdata-0.1.1.tar.gz.
File metadata
- Download URL: brasa_marketdata-0.1.1.tar.gz
- Upload date:
- Size: 229.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eb133f6e031280b22d8791d52659f18844990c8b7a57a13773a96cebf15171aa
|
|
| MD5 |
770fdb462961eaf5f585aa3ac87c3c64
|
|
| BLAKE2b-256 |
6e7a6b9f08f24e9a765bf58046ab7ac578a6af2b300db409e7ad3c8fd914e2fa
|
File details
Details for the file brasa_marketdata-0.1.1-py3-none-any.whl.
File metadata
- Download URL: brasa_marketdata-0.1.1-py3-none-any.whl
- Upload date:
- Size: 307.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.9 {"installer":{"name":"uv","version":"0.9.9"},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3d7547f29c1a16f933635feeb99daff3175afca63b10d88b70f8748aaa1e6469
|
|
| MD5 |
3462c491d8d7040114bad1489d5a9f4e
|
|
| BLAKE2b-256 |
b6e230eee89362f81223b7fa7ad37b051924e34958e6c47358f49cc7aab0e538
|