Shared models, strategy framework, and DB session for Pulse.
Project description
pulse-core
Shared models, strategy framework, and DB session for Pulse.
This package is the foundation layer consumed by both pulse-backend (FastAPI) and Airflow DAGs. It owns the SQLModel/SQLAlchemy models, the strategy engine abstraction, and a lightweight DB session factory.
Package structure
pulse_core/
├── db.py # Singleton engine + context-managed Session
├── models/
│ ├── engine.py # Engine table (registry metadata)
│ ├── market.py # Exchange, Instrument, Listing, DataSource
│ ├── mixins.py # TimestampMixin, SoftDeleteMixin
│ ├── prices.py # TimeFrame, PriceOHLCV
│ └── signals.py # Strategy, Signal, Subscription, Delivery*
└── strategies/
├── base.py # BaseStrategy ABC, SignalOutput, UniverseFilter
├── indicators.py # Pure-numpy indicator library (SMA, ADX, BB, …)
├── registry.py # StrategyRegistry (decorator-based)
├── sync.py # sync_engine_registry() — Python ↔ DB reconciliation
└── engines/
├── mean_reversion.py # Dual MA mean-reversion
└── regime_mean_reversion.py # Regime-based probabilistic mean-reversion
Installation
# from the repo root
uv pip install -e pulse-core
Or as a dependency in another package's pyproject.toml:
dependencies = [
"pulse-core @ file:///${PROJECT_ROOT}/pulse-core",
]
Usage
Database session
from pulse_core.db import get_session
# Reads PULSE_DB_URL from the environment
with get_session() as session:
...
Models
from pulse_core.models import Listing, PriceOHLCV, Signal, Engine
Writing a strategy engine
Subclass BaseStrategy, implement validate_parameters() and compute(), then register it with the @StrategyRegistry.register decorator:
from pulse_core.strategies import BaseStrategy, SignalOutput, StrategyRegistry
@StrategyRegistry.register("my_engine")
class MyEngine(BaseStrategy):
display_name = "My Engine"
description = "Short description of the strategy."
def validate_parameters(self) -> None:
# raise ValueError if self.parameters is invalid
...
def compute(self, listing, candles, as_of) -> SignalOutput | None:
# return a SignalOutput or None
...
The engine is auto-discovered at import time via pulse_core.strategies.engines.__init__.
Syncing the registry to the database
from pulse_core.db import get_session
from pulse_core.strategies.sync import sync_engine_registry
with get_session() as session:
result = sync_engine_registry(session)
print(f"upserted={result.upserted}, deactivated={result.deactivated}")
Requirements
- Python >= 3.12
- PostgreSQL (TimescaleDB) — connected via
PULSE_DB_URL
Development
# lint
uv run --group dev ruff check .
# tests
uv run --group test pytest
Project details
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 pulse_core-0.1.2.tar.gz.
File metadata
- Download URL: pulse_core-0.1.2.tar.gz
- Upload date:
- Size: 51.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"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 |
9156da1b0c1c48ba420af99c4b0b6150e2447b79754d7a8c3bc4a166c6711ca3
|
|
| MD5 |
fd3323dd0175ff9fa1015641d4399213
|
|
| BLAKE2b-256 |
714c721db4fdbd40f2d1d54a351dc220e58bcf862c0994636e6e1b37e44ccb5c
|
File details
Details for the file pulse_core-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pulse_core-0.1.2-py3-none-any.whl
- Upload date:
- Size: 29.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"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 |
0b16a93725f445f763988bb77c6ba2fa7ed9a1eceabad1bb28a0518cc80c511c
|
|
| MD5 |
06c5ff9a860b0eaf0beef502a0a680c2
|
|
| BLAKE2b-256 |
e07b853c91f95806291a514fa3d5250818e0f0cbdf7037e24f785cd95fa803c7
|