brain-store
Dual-mode persistence layer (PostgreSQL connection pool + flat-file fallback) and RL state store for Brain Alpha pipelines.
brain_store provides resilient, dual-mode persistence for quantitative alpha pipelines. It connects to Neon PostgreSQL with connection pooling via psycopg_pool while falling back automatically to local zero-config JSON/CSV file storage when DATABASE_URL is absent. For the complete relational entity-relationship diagram and database migration operations, see Schema & Migrations.
Installation
pip install brain-store
Quickstart
from brain_store import AlphaStore
# Connects to PostgreSQL if DATABASE_URL is set, otherwise uses ./data/
store = AlphaStore(data_dir="./data")
# Save a qualified alpha
store.save_qualified_alpha({
"expression": "group_neutralize(rank(close), subindustry)",
"sharpe": 1.85,
"fitness": 1.42,
})
# Load historical expressions with pagination to prevent OOM
evaluated = store.load_evaluated_expressions(limit=500, offset=0)
print(f"Loaded {len(evaluated)} evaluated expressions.")
Note:
OptionsStoreis preserved as a backward-compatible alias forAlphaStore.
Architecture
brain_store/
├── brain_store/
│ ├── __init__.py # Public re-exports (AlphaStore, OptionsStore, OptionsDatabase)
│ ├── db.py # OptionsDatabase — connection pool, 9-table DDL, RL state
│ ├── store.py # AlphaStore — high-level dual-mode facade
│ ├── py.typed # PEP 561 typing marker
│ └── migrations/ # DDL migration scripts
├── tests/ # Offline unit tests (no PostgreSQL instance required)
└── docs/
├── API.md # Complete API specification
└── SCHEMA_AND_MIGRATIONS.md # Relational schema diagram & migration runbook
Database Schema
| Table | Purpose | Indexing Strategy |
|---|---|---|
options_alphas |
Live alpha reserve vault | Unique on alpha_id, Index on status, category |
options_evaluations |
Simulation backtest audit log | Index on alpha_id, simulated_at |
options_strategy_rl_state |
Strategy-level reinforcement learning operator weights | Primary key on strategy_name |
options_learning_memory |
Global Multi-Armed Bandit expression reward tracking | Primary key on expression_hash |
options_rejected_alphas |
Diagnostics for checklist / gate-failed alphas | Index on failure_reason |
options_correlated_alphas |
Audit log of correlation gate rejections ( | rho |
cluster_session_cache |
Distributed BRAIN auth session token caching (2h TTL) | Primary key on session_key |
cluster_run_lock |
Distributed mutex preventing duplicate simulation runs | Primary key on lock_name |
org_runs |
Runner heartbeat and telemetry monitoring | Primary key on run_id |
Testing
pytest tests/ -v
Tests run offline without requiring a live PostgreSQL instance.
Security
Report vulnerabilities per SECURITY.md.
Contributing
See CONTRIBUTING.md for contribution guidelines.
License
Released under the MIT License. Maintained by Xtley001.
Metadata
Release files for brain-store 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| brain_store-0.1.0.tar.gz | 14.4 kB | Without provenance | Details for brain_store-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| brain_store-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for brain_store-0.1.0-py3-none-any.whl |
Total release size: 26.7 kB
Release files / brain_store-0.1.0.tar.gz
| Download URL | brain_store-0.1.0.tar.gz |
|---|---|
| Size | 14.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3dbec63753ce332ec56574718e4aa9199d198788d09a065280efbbbdd512eecd
|
|
BLAKE2b-256 checksum How to use checksums |
7dc02165070afa500c50f06481e95284a513f6c22e1275259cb97f545a38128c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Release files / brain_store-0.1.0-py3-none-any.whl
| Download URL | brain_store-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b1e7495dd26d522c770b1749d753d108b3811d9d5f1b98a66028b92d8e379cd
|
|
BLAKE2b-256 checksum How to use checksums |
079af7a93fc868c56516a3b34a71fd443c46bbbb365175a3c132dad207c29616
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.7
|
Security for brain-store 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.