brasa-core 0.5.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.
- brasa_core-0.5.0/.gitignore +143 -0
- brasa_core-0.5.0/LICENSE +21 -0
- brasa_core-0.5.0/PKG-INFO +170 -0
- brasa_core-0.5.0/README.md +146 -0
- brasa_core-0.5.0/brasa/__init__.py +53 -0
- brasa_core-0.5.0/brasa/__main__.py +6 -0
- brasa_core-0.5.0/brasa/cli.py +1750 -0
- brasa_core-0.5.0/brasa/downloaders/__init__.py +35 -0
- brasa_core-0.5.0/brasa/downloaders/downloaders.py +273 -0
- brasa_core-0.5.0/brasa/downloaders/helpers.py +185 -0
- brasa_core-0.5.0/brasa/engine/__init__.py +181 -0
- brasa_core-0.5.0/brasa/engine/api.py +867 -0
- brasa_core-0.5.0/brasa/engine/cache.py +858 -0
- brasa_core-0.5.0/brasa/engine/catalog.py +531 -0
- brasa_core-0.5.0/brasa/engine/config.py +93 -0
- brasa_core-0.5.0/brasa/engine/core.py +78 -0
- brasa_core-0.5.0/brasa/engine/dependency_graph.py +904 -0
- brasa_core-0.5.0/brasa/engine/dependency_resolver.py +363 -0
- brasa_core-0.5.0/brasa/engine/doctor.py +1319 -0
- brasa_core-0.5.0/brasa/engine/download.py +190 -0
- brasa_core-0.5.0/brasa/engine/download_plan.py +746 -0
- brasa_core-0.5.0/brasa/engine/duck.py +58 -0
- brasa_core-0.5.0/brasa/engine/exceptions.py +97 -0
- brasa_core-0.5.0/brasa/engine/layers.py +66 -0
- brasa_core-0.5.0/brasa/engine/orchestrator.py +699 -0
- brasa_core-0.5.0/brasa/engine/pipeline/__init__.py +53 -0
- brasa_core-0.5.0/brasa/engine/pipeline/context.py +118 -0
- brasa_core-0.5.0/brasa/engine/pipeline/etl_context.py +55 -0
- brasa_core-0.5.0/brasa/engine/pipeline/etl_executor.py +232 -0
- brasa_core-0.5.0/brasa/engine/pipeline/etl_results.py +24 -0
- brasa_core-0.5.0/brasa/engine/pipeline/executor.py +143 -0
- brasa_core-0.5.0/brasa/engine/pipeline/registry.py +96 -0
- brasa_core-0.5.0/brasa/engine/pipeline/step.py +116 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/__init__.py +29 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/b3_steps.py +700 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/column_steps.py +156 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/custom_steps.py +80 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/etl_steps.py +608 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/html_steps.py +66 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/io_steps.py +213 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/shared_transforms.py +449 -0
- brasa_core-0.5.0/brasa/engine/pipeline/steps/transform_steps.py +308 -0
- brasa_core-0.5.0/brasa/engine/pipeline_map.py +201 -0
- brasa_core-0.5.0/brasa/engine/processing.py +189 -0
- brasa_core-0.5.0/brasa/engine/reporting.py +727 -0
- brasa_core-0.5.0/brasa/engine/resources.py +32 -0
- brasa_core-0.5.0/brasa/engine/template.py +1141 -0
- brasa_core-0.5.0/brasa/engine/template_git.py +153 -0
- brasa_core-0.5.0/brasa/engine/update_strategy.py +347 -0
- brasa_core-0.5.0/brasa/engine/validations.py +794 -0
- brasa_core-0.5.0/brasa/fieldsets/__init__.py +18 -0
- brasa_core-0.5.0/brasa/fieldsets/adapters/__init__.py +9 -0
- brasa_core-0.5.0/brasa/fieldsets/adapters/pandas_adapter.py +180 -0
- brasa_core-0.5.0/brasa/fieldsets/adapters/pyarrow_adapter.py +32 -0
- brasa_core-0.5.0/brasa/fieldsets/field.py +251 -0
- brasa_core-0.5.0/brasa/fieldsets/fieldset.py +224 -0
- brasa_core-0.5.0/brasa/fieldsets/type_parser.py +372 -0
- brasa_core-0.5.0/brasa/files/sql/create-dataset-catalog.sql +21 -0
- brasa_core-0.5.0/brasa/files/sql/create-meta-db.sql +24 -0
- brasa_core-0.5.0/brasa/parsers/__init__.py +0 -0
- brasa_core-0.5.0/brasa/parsers/b3/__init__.py +0 -0
- brasa_core-0.5.0/brasa/parsers/b3/futures_settlement_prices.py +78 -0
- brasa_core-0.5.0/brasa/queries.py +988 -0
- brasa_core-0.5.0/brasa/util.py +448 -0
- brasa_core-0.5.0/pyproject.toml +149 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
# Byte-compiled / optimized / DLL files
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
|
|
6
|
+
# C extensions
|
|
7
|
+
*.so
|
|
8
|
+
|
|
9
|
+
# Distribution / packaging
|
|
10
|
+
.Python
|
|
11
|
+
build/
|
|
12
|
+
develop-eggs/
|
|
13
|
+
dist/
|
|
14
|
+
downloads/
|
|
15
|
+
eggs/
|
|
16
|
+
.eggs/
|
|
17
|
+
lib/
|
|
18
|
+
lib64/
|
|
19
|
+
parts/
|
|
20
|
+
sdist/
|
|
21
|
+
var/
|
|
22
|
+
wheels/
|
|
23
|
+
pip-wheel-metadata/
|
|
24
|
+
share/python-wheels/
|
|
25
|
+
*.egg-info/
|
|
26
|
+
.installed.cfg
|
|
27
|
+
*.egg
|
|
28
|
+
MANIFEST
|
|
29
|
+
|
|
30
|
+
# PyInstaller
|
|
31
|
+
# Usually these files are written by a python script from a template
|
|
32
|
+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
|
|
33
|
+
*.manifest
|
|
34
|
+
*.spec
|
|
35
|
+
|
|
36
|
+
# Installer logs
|
|
37
|
+
pip-log.txt
|
|
38
|
+
pip-delete-this-directory.txt
|
|
39
|
+
|
|
40
|
+
# Unit test / coverage reports
|
|
41
|
+
htmlcov/
|
|
42
|
+
.tox/
|
|
43
|
+
.nox/
|
|
44
|
+
.coverage
|
|
45
|
+
.coverage.*
|
|
46
|
+
.cache
|
|
47
|
+
nosetests.xml
|
|
48
|
+
coverage.xml
|
|
49
|
+
*.cover
|
|
50
|
+
*.py,cover
|
|
51
|
+
.hypothesis/
|
|
52
|
+
.pytest_cache/
|
|
53
|
+
|
|
54
|
+
# Translations
|
|
55
|
+
*.mo
|
|
56
|
+
*.pot
|
|
57
|
+
|
|
58
|
+
# Django stuff:
|
|
59
|
+
*.log
|
|
60
|
+
local_settings.py
|
|
61
|
+
db.sqlite3
|
|
62
|
+
db.sqlite3-journal
|
|
63
|
+
|
|
64
|
+
# Flask stuff:
|
|
65
|
+
instance/
|
|
66
|
+
.webassets-cache
|
|
67
|
+
|
|
68
|
+
# Scrapy stuff:
|
|
69
|
+
.scrapy
|
|
70
|
+
|
|
71
|
+
# Sphinx documentation
|
|
72
|
+
docs/_build/
|
|
73
|
+
|
|
74
|
+
# PyBuilder
|
|
75
|
+
target/
|
|
76
|
+
|
|
77
|
+
# Jupyter Notebook
|
|
78
|
+
.ipynb_checkpoints
|
|
79
|
+
|
|
80
|
+
# IPython
|
|
81
|
+
profile_default/
|
|
82
|
+
ipython_config.py
|
|
83
|
+
|
|
84
|
+
# pyenv
|
|
85
|
+
.python-version
|
|
86
|
+
|
|
87
|
+
# pipenv
|
|
88
|
+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
|
|
89
|
+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
|
|
90
|
+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
|
|
91
|
+
# install all needed dependencies.
|
|
92
|
+
#Pipfile.lock
|
|
93
|
+
|
|
94
|
+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
|
|
95
|
+
__pypackages__/
|
|
96
|
+
|
|
97
|
+
# Celery stuff
|
|
98
|
+
celerybeat-schedule
|
|
99
|
+
celerybeat.pid
|
|
100
|
+
|
|
101
|
+
# SageMath parsed files
|
|
102
|
+
*.sage.py
|
|
103
|
+
|
|
104
|
+
# Environments
|
|
105
|
+
.env
|
|
106
|
+
.venv
|
|
107
|
+
env/
|
|
108
|
+
venv/
|
|
109
|
+
ENV/
|
|
110
|
+
env.bak/
|
|
111
|
+
venv.bak/
|
|
112
|
+
|
|
113
|
+
# Spyder project settings
|
|
114
|
+
.spyderproject
|
|
115
|
+
.spyproject
|
|
116
|
+
|
|
117
|
+
# Rope project settings
|
|
118
|
+
.ropeproject
|
|
119
|
+
|
|
120
|
+
# mkdocs documentation
|
|
121
|
+
/site
|
|
122
|
+
|
|
123
|
+
# mypy
|
|
124
|
+
.mypy_cache/
|
|
125
|
+
.dmypy.json
|
|
126
|
+
dmypy.json
|
|
127
|
+
|
|
128
|
+
# Pyre type checker
|
|
129
|
+
.pyre/
|
|
130
|
+
|
|
131
|
+
# Git worktrees
|
|
132
|
+
.worktrees/
|
|
133
|
+
|
|
134
|
+
data/big-files/BDIN.zip
|
|
135
|
+
data/big-files/OpcoesAcoesEmAberto.zip
|
|
136
|
+
legacy/
|
|
137
|
+
.brasa-cache/
|
|
138
|
+
.vscode/launch.json
|
|
139
|
+
|
|
140
|
+
# Generated skill lockfile and script outputs
|
|
141
|
+
skills-lock.json
|
|
142
|
+
scripts/out/
|
|
143
|
+
tmp/
|
brasa_core-0.5.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Wilson Freitas
|
|
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,170 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: brasa-core
|
|
3
|
+
Version: 0.5.0
|
|
4
|
+
Summary: Template-driven ETL engine: download, parse, transform and query datasets described by YAML templates (official templates for Brazilian market and economic data: brasa-templates).
|
|
5
|
+
Author-email: wilsonfreitas <wilson.freitas@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
License-File: LICENSE
|
|
8
|
+
Requires-Python: >=3.11
|
|
9
|
+
Requires-Dist: bizdays>=1.0.15
|
|
10
|
+
Requires-Dist: duckdb>=1.2.0
|
|
11
|
+
Requires-Dist: lxml>=4.9.2
|
|
12
|
+
Requires-Dist: numpy>=2.0.0
|
|
13
|
+
Requires-Dist: openpyxl>=3.1.5
|
|
14
|
+
Requires-Dist: packaging>=23.0
|
|
15
|
+
Requires-Dist: pandas>=2.0.0
|
|
16
|
+
Requires-Dist: platformdirs>=4.0.0
|
|
17
|
+
Requires-Dist: pyarrow>=19.0.0
|
|
18
|
+
Requires-Dist: python-bcb>=0.4.1
|
|
19
|
+
Requires-Dist: pyyaml>=6.0
|
|
20
|
+
Requires-Dist: regexparser>=0.1.0
|
|
21
|
+
Requires-Dist: requests>=2.28.0
|
|
22
|
+
Requires-Dist: rich>=13.0.0
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
25
|
+
# brasa
|
|
26
|
+
|
|
27
|
+
A template-driven ETL engine: download, parse, transform and query datasets
|
|
28
|
+
described by YAML templates. The official templates —
|
|
29
|
+
[brasa-templates](https://github.com/wilsonfreitas/brasa-templates) — cover
|
|
30
|
+
Brazilian market and economic data (B3, ANBIMA, CVM, BCB).
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
Install from PyPI as `brasa-core` (the import name and the command are `brasa`),
|
|
35
|
+
then run `brasa init` to choose a data directory and get the templates:
|
|
36
|
+
|
|
37
|
+
pip install brasa-core
|
|
38
|
+
brasa init
|
|
39
|
+
|
|
40
|
+
Until 0.4.0 the distribution was called `brasa-marketdata`; since 0.5.0 it is
|
|
41
|
+
`brasa-core`, and the templates live in brasa-templates instead of the package.
|
|
42
|
+
|
|
43
|
+
Or directly from GitHub (latest `main`):
|
|
44
|
+
|
|
45
|
+
pip install git+https://github.com/wilsonfreitas/brasa.git
|
|
46
|
+
|
|
47
|
+
With `uv`:
|
|
48
|
+
|
|
49
|
+
uv add brasa-core
|
|
50
|
+
uv add git+https://github.com/wilsonfreitas/brasa.git
|
|
51
|
+
|
|
52
|
+
## Data directory (`brasa init` / `BRASA_DATA_PATH`)
|
|
53
|
+
|
|
54
|
+
brasa stores everything — raw downloads, parsed parquet, and the metadata DB —
|
|
55
|
+
under a single *brasa home*. On a fresh install, configure it once:
|
|
56
|
+
|
|
57
|
+
brasa init
|
|
58
|
+
|
|
59
|
+
This suggests a platform default (e.g. `~/.local/share/brasa` on Linux),
|
|
60
|
+
lets you confirm or type another path, and persists the choice in
|
|
61
|
+
`~/.config/brasa/config.toml`. It also sets up your templates: it clones the
|
|
62
|
+
official [brasa-templates](https://github.com/wilsonfreitas/brasa-templates)
|
|
63
|
+
repo into `<data path>/templates` (use `--templates <url|path>` for a fork or
|
|
64
|
+
a folder you already have). Get template updates later with
|
|
65
|
+
`brasa update-templates`. Non-interactive variants:
|
|
66
|
+
|
|
67
|
+
brasa init --data-path /data/brasa # explicit path, no prompt
|
|
68
|
+
brasa init --yes # accept the default, no prompt
|
|
69
|
+
|
|
70
|
+
The `BRASA_DATA_PATH` environment variable, when set, always takes
|
|
71
|
+
precedence over the config file — useful for CI, containers, tests, and
|
|
72
|
+
one-off overrides. Commands that read or write data fail with a clear
|
|
73
|
+
error until one of the two is configured; template introspection commands
|
|
74
|
+
(`list-templates`, `deps`, `graph`) work without any configuration.
|
|
75
|
+
|
|
76
|
+
Templates can live in your own template folders too (`BRASA_TEMPLATE_PATH`
|
|
77
|
+
or `template_path` in the config file). Templates are code — they can run
|
|
78
|
+
Python — so only add folders you trust; see
|
|
79
|
+
[Template folders](docs/TEMPLATES.md#template-folders).
|
|
80
|
+
|
|
81
|
+
## Changelog
|
|
82
|
+
|
|
83
|
+
### Deterministic Download Status Codes
|
|
84
|
+
|
|
85
|
+
Every download attempt is now classified with a single, unambiguous status code
|
|
86
|
+
persisted in the `download_trials` table:
|
|
87
|
+
|
|
88
|
+
| Symbol | Name | Trigger |
|
|
89
|
+
|--------|------------|---------------------------------------------------|
|
|
90
|
+
| `.` | PASSED | Successful download |
|
|
91
|
+
| `F` | FAILED | Expected failure (`DownloadException`) |
|
|
92
|
+
| `E` | ERROR | Unexpected exception |
|
|
93
|
+
| `S` | SKIPPED | Skipped (cache hit / invalid / duplicated) |
|
|
94
|
+
| `D` | DUPLICATED | Raw folder already exists |
|
|
95
|
+
| `I` | INVALID | Content validation failure |
|
|
96
|
+
| `W` | WARNING | Success with warnings |
|
|
97
|
+
|
|
98
|
+
**DB migration**: Existing caches are upgraded automatically on startup.
|
|
99
|
+
Legacy `downloaded=1` rows become `PASSED`; `downloaded=0` become `FAILED`.
|
|
100
|
+
(The standalone migration script has been removed after being applied; it is
|
|
101
|
+
recoverable from git history if ever needed.)
|
|
102
|
+
|
|
103
|
+
See [docs/USER_GUIDE.md](docs/USER_GUIDE.md#download-status-codes) for full details.
|
|
104
|
+
|
|
105
|
+
### Import Local Files (`import_marketdata` / `brasa import`)
|
|
106
|
+
|
|
107
|
+
Files with no download URL — a one-off vendor file, a manually-provided upload,
|
|
108
|
+
or a corrected file for backfill — can now be imported using the same
|
|
109
|
+
validate → gzip → checksum-dedup → parse → store engine as `download`. Only
|
|
110
|
+
the acquisition step changes: bytes are read from disk instead of HTTP.
|
|
111
|
+
|
|
112
|
+
```bash
|
|
113
|
+
# Backfill a single date into a template that normally downloads via HTTP
|
|
114
|
+
brasa import b3-cotahist-daily --path /data/backfill/COTAHIST_D02012024.TXT --arg refdate=2024-01-02
|
|
115
|
+
|
|
116
|
+
# Bulk import one file per business day using a date pattern
|
|
117
|
+
brasa import my-daily-template --path '/data/prices/%Y-%m-%d.csv' --arg refdate=@2026-06-01:2026-06-30
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
```python
|
|
121
|
+
from brasa import import_marketdata
|
|
122
|
+
|
|
123
|
+
import_marketdata("b3-cotahist-daily", path="/data/backfill/COTAHIST_D02012024.TXT", refdate="2024-01-02")
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
See [docs/CLI.md](docs/CLI.md#import), [docs/API_REFERENCE.md](docs/API_REFERENCE.md#data-import),
|
|
127
|
+
and [docs/TEMPLATES.md](docs/TEMPLATES.md#importing-local-files-importer) for full details.
|
|
128
|
+
|
|
129
|
+
## Publishing to PyPI
|
|
130
|
+
|
|
131
|
+
brasa is built with [hatchling](https://hatch.pypa.io/) and published manually
|
|
132
|
+
under the distribution name `brasa-core` (the PyPI name `brasa` was already
|
|
133
|
+
taken by an unrelated project; `import brasa` is unaffected; until 0.4.0 the
|
|
134
|
+
name was `brasa-marketdata`). The SQL DDL ships inside the package
|
|
135
|
+
(`brasa/files/sql/`); templates do not — they live in brasa-templates.
|
|
136
|
+
|
|
137
|
+
1. Bump `version` in `pyproject.toml`.
|
|
138
|
+
2. Build the wheel and sdist:
|
|
139
|
+
|
|
140
|
+
```bash
|
|
141
|
+
uv build
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Distributions are written to `dist/`.
|
|
145
|
+
|
|
146
|
+
3. (Optional) Verify the wheel ships the SQL files and no templates:
|
|
147
|
+
|
|
148
|
+
```bash
|
|
149
|
+
BRASA_BUILD_TEST=1 uv run pytest tests/test_packaging_wheel.py -v
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
4. (Optional) Smoke-test in a clean environment:
|
|
153
|
+
|
|
154
|
+
```bash
|
|
155
|
+
python -m venv /tmp/brasa-smoke
|
|
156
|
+
/tmp/brasa-smoke/bin/pip install dist/brasa_core-*.whl
|
|
157
|
+
/tmp/brasa-smoke/bin/brasa --version
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
5. Publish:
|
|
161
|
+
|
|
162
|
+
```bash
|
|
163
|
+
# TestPyPI dry-run first (recommended)
|
|
164
|
+
uv publish --publish-url https://test.pypi.org/legacy/ --token "$TEST_PYPI_TOKEN"
|
|
165
|
+
# Production
|
|
166
|
+
uv publish --token "$UV_PUBLISH_TOKEN"
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
A PyPI API token can be supplied via `--token`, the `UV_PUBLISH_TOKEN`
|
|
170
|
+
environment variable, or `~/.pypirc`.
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
# brasa
|
|
2
|
+
|
|
3
|
+
A template-driven ETL engine: download, parse, transform and query datasets
|
|
4
|
+
described by YAML templates. The official templates —
|
|
5
|
+
[brasa-templates](https://github.com/wilsonfreitas/brasa-templates) — cover
|
|
6
|
+
Brazilian market and economic data (B3, ANBIMA, CVM, BCB).
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Install from PyPI as `brasa-core` (the import name and the command are `brasa`),
|
|
11
|
+
then run `brasa init` to choose a data directory and get the templates:
|
|
12
|
+
|
|
13
|
+
pip install brasa-core
|
|
14
|
+
brasa init
|
|
15
|
+
|
|
16
|
+
Until 0.4.0 the distribution was called `brasa-marketdata`; since 0.5.0 it is
|
|
17
|
+
`brasa-core`, and the templates live in brasa-templates instead of the package.
|
|
18
|
+
|
|
19
|
+
Or directly from GitHub (latest `main`):
|
|
20
|
+
|
|
21
|
+
pip install git+https://github.com/wilsonfreitas/brasa.git
|
|
22
|
+
|
|
23
|
+
With `uv`:
|
|
24
|
+
|
|
25
|
+
uv add brasa-core
|
|
26
|
+
uv add git+https://github.com/wilsonfreitas/brasa.git
|
|
27
|
+
|
|
28
|
+
## Data directory (`brasa init` / `BRASA_DATA_PATH`)
|
|
29
|
+
|
|
30
|
+
brasa stores everything — raw downloads, parsed parquet, and the metadata DB —
|
|
31
|
+
under a single *brasa home*. On a fresh install, configure it once:
|
|
32
|
+
|
|
33
|
+
brasa init
|
|
34
|
+
|
|
35
|
+
This suggests a platform default (e.g. `~/.local/share/brasa` on Linux),
|
|
36
|
+
lets you confirm or type another path, and persists the choice in
|
|
37
|
+
`~/.config/brasa/config.toml`. It also sets up your templates: it clones the
|
|
38
|
+
official [brasa-templates](https://github.com/wilsonfreitas/brasa-templates)
|
|
39
|
+
repo into `<data path>/templates` (use `--templates <url|path>` for a fork or
|
|
40
|
+
a folder you already have). Get template updates later with
|
|
41
|
+
`brasa update-templates`. Non-interactive variants:
|
|
42
|
+
|
|
43
|
+
brasa init --data-path /data/brasa # explicit path, no prompt
|
|
44
|
+
brasa init --yes # accept the default, no prompt
|
|
45
|
+
|
|
46
|
+
The `BRASA_DATA_PATH` environment variable, when set, always takes
|
|
47
|
+
precedence over the config file — useful for CI, containers, tests, and
|
|
48
|
+
one-off overrides. Commands that read or write data fail with a clear
|
|
49
|
+
error until one of the two is configured; template introspection commands
|
|
50
|
+
(`list-templates`, `deps`, `graph`) work without any configuration.
|
|
51
|
+
|
|
52
|
+
Templates can live in your own template folders too (`BRASA_TEMPLATE_PATH`
|
|
53
|
+
or `template_path` in the config file). Templates are code — they can run
|
|
54
|
+
Python — so only add folders you trust; see
|
|
55
|
+
[Template folders](docs/TEMPLATES.md#template-folders).
|
|
56
|
+
|
|
57
|
+
## Changelog
|
|
58
|
+
|
|
59
|
+
### Deterministic Download Status Codes
|
|
60
|
+
|
|
61
|
+
Every download attempt is now classified with a single, unambiguous status code
|
|
62
|
+
persisted in the `download_trials` table:
|
|
63
|
+
|
|
64
|
+
| Symbol | Name | Trigger |
|
|
65
|
+
|--------|------------|---------------------------------------------------|
|
|
66
|
+
| `.` | PASSED | Successful download |
|
|
67
|
+
| `F` | FAILED | Expected failure (`DownloadException`) |
|
|
68
|
+
| `E` | ERROR | Unexpected exception |
|
|
69
|
+
| `S` | SKIPPED | Skipped (cache hit / invalid / duplicated) |
|
|
70
|
+
| `D` | DUPLICATED | Raw folder already exists |
|
|
71
|
+
| `I` | INVALID | Content validation failure |
|
|
72
|
+
| `W` | WARNING | Success with warnings |
|
|
73
|
+
|
|
74
|
+
**DB migration**: Existing caches are upgraded automatically on startup.
|
|
75
|
+
Legacy `downloaded=1` rows become `PASSED`; `downloaded=0` become `FAILED`.
|
|
76
|
+
(The standalone migration script has been removed after being applied; it is
|
|
77
|
+
recoverable from git history if ever needed.)
|
|
78
|
+
|
|
79
|
+
See [docs/USER_GUIDE.md](docs/USER_GUIDE.md#download-status-codes) for full details.
|
|
80
|
+
|
|
81
|
+
### Import Local Files (`import_marketdata` / `brasa import`)
|
|
82
|
+
|
|
83
|
+
Files with no download URL — a one-off vendor file, a manually-provided upload,
|
|
84
|
+
or a corrected file for backfill — can now be imported using the same
|
|
85
|
+
validate → gzip → checksum-dedup → parse → store engine as `download`. Only
|
|
86
|
+
the acquisition step changes: bytes are read from disk instead of HTTP.
|
|
87
|
+
|
|
88
|
+
```bash
|
|
89
|
+
# Backfill a single date into a template that normally downloads via HTTP
|
|
90
|
+
brasa import b3-cotahist-daily --path /data/backfill/COTAHIST_D02012024.TXT --arg refdate=2024-01-02
|
|
91
|
+
|
|
92
|
+
# Bulk import one file per business day using a date pattern
|
|
93
|
+
brasa import my-daily-template --path '/data/prices/%Y-%m-%d.csv' --arg refdate=@2026-06-01:2026-06-30
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
from brasa import import_marketdata
|
|
98
|
+
|
|
99
|
+
import_marketdata("b3-cotahist-daily", path="/data/backfill/COTAHIST_D02012024.TXT", refdate="2024-01-02")
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
See [docs/CLI.md](docs/CLI.md#import), [docs/API_REFERENCE.md](docs/API_REFERENCE.md#data-import),
|
|
103
|
+
and [docs/TEMPLATES.md](docs/TEMPLATES.md#importing-local-files-importer) for full details.
|
|
104
|
+
|
|
105
|
+
## Publishing to PyPI
|
|
106
|
+
|
|
107
|
+
brasa is built with [hatchling](https://hatch.pypa.io/) and published manually
|
|
108
|
+
under the distribution name `brasa-core` (the PyPI name `brasa` was already
|
|
109
|
+
taken by an unrelated project; `import brasa` is unaffected; until 0.4.0 the
|
|
110
|
+
name was `brasa-marketdata`). The SQL DDL ships inside the package
|
|
111
|
+
(`brasa/files/sql/`); templates do not — they live in brasa-templates.
|
|
112
|
+
|
|
113
|
+
1. Bump `version` in `pyproject.toml`.
|
|
114
|
+
2. Build the wheel and sdist:
|
|
115
|
+
|
|
116
|
+
```bash
|
|
117
|
+
uv build
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
Distributions are written to `dist/`.
|
|
121
|
+
|
|
122
|
+
3. (Optional) Verify the wheel ships the SQL files and no templates:
|
|
123
|
+
|
|
124
|
+
```bash
|
|
125
|
+
BRASA_BUILD_TEST=1 uv run pytest tests/test_packaging_wheel.py -v
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
4. (Optional) Smoke-test in a clean environment:
|
|
129
|
+
|
|
130
|
+
```bash
|
|
131
|
+
python -m venv /tmp/brasa-smoke
|
|
132
|
+
/tmp/brasa-smoke/bin/pip install dist/brasa_core-*.whl
|
|
133
|
+
/tmp/brasa-smoke/bin/brasa --version
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
5. Publish:
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
# TestPyPI dry-run first (recommended)
|
|
140
|
+
uv publish --publish-url https://test.pypi.org/legacy/ --token "$TEST_PYPI_TOKEN"
|
|
141
|
+
# Production
|
|
142
|
+
uv publish --token "$UV_PUBLISH_TOKEN"
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
A PyPI API token can be supplied via `--token`, the `UV_PUBLISH_TOKEN`
|
|
146
|
+
environment variable, or `~/.pypirc`.
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
from .engine import (
|
|
2
|
+
CacheManager,
|
|
3
|
+
DownloadPlan,
|
|
4
|
+
Verbosity,
|
|
5
|
+
download_marketdata,
|
|
6
|
+
execute_download_plan,
|
|
7
|
+
get_marketdata,
|
|
8
|
+
import_marketdata,
|
|
9
|
+
process_etl,
|
|
10
|
+
process_marketdata,
|
|
11
|
+
retrieve_template,
|
|
12
|
+
)
|
|
13
|
+
from .queries import (
|
|
14
|
+
BrasaDB,
|
|
15
|
+
create_all_views,
|
|
16
|
+
describe,
|
|
17
|
+
describe_dataset,
|
|
18
|
+
get_dataset,
|
|
19
|
+
get_industry_sectors,
|
|
20
|
+
get_prices,
|
|
21
|
+
get_returns,
|
|
22
|
+
get_symbols,
|
|
23
|
+
list_datasets,
|
|
24
|
+
show,
|
|
25
|
+
sql,
|
|
26
|
+
write_dataset,
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
__all__ = [
|
|
30
|
+
"BrasaDB",
|
|
31
|
+
"CacheManager",
|
|
32
|
+
"DownloadPlan",
|
|
33
|
+
"Verbosity",
|
|
34
|
+
"create_all_views",
|
|
35
|
+
"describe",
|
|
36
|
+
"describe_dataset",
|
|
37
|
+
"download_marketdata",
|
|
38
|
+
"execute_download_plan",
|
|
39
|
+
"get_dataset",
|
|
40
|
+
"get_industry_sectors",
|
|
41
|
+
"get_marketdata",
|
|
42
|
+
"get_prices",
|
|
43
|
+
"get_returns",
|
|
44
|
+
"get_symbols",
|
|
45
|
+
"import_marketdata",
|
|
46
|
+
"list_datasets",
|
|
47
|
+
"process_etl",
|
|
48
|
+
"process_marketdata",
|
|
49
|
+
"retrieve_template",
|
|
50
|
+
"show",
|
|
51
|
+
"sql",
|
|
52
|
+
"write_dataset",
|
|
53
|
+
]
|