Skip to main content

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

pulse_core-0.1.0.tar.gz (49.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pulse_core-0.1.0-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

Details for the file pulse_core-0.1.0.tar.gz.

File metadata

  • Download URL: pulse_core-0.1.0.tar.gz
  • Upload date:
  • Size: 49.7 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

Hashes for pulse_core-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6cd8bebc6ed5232e06116d1cba7bcb78c33d5ffe56a24c8857fdfae906df35f4
MD5 7451c0b468748d969f12d48a445a88e6
BLAKE2b-256 c813871defb6fe4f793b1fd5171e8747f74a3e6bf4113d695118ed297eba7195

See more details on using hashes here.

File details

Details for the file pulse_core-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pulse_core-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.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

Hashes for pulse_core-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 71a0deb756745152231d0778f098248d7fe78c766b2000659b6d171b11e4a831
MD5 105573526bc0dfd69459771231fde58c
BLAKE2b-256 173a37d01769cdc1d11b90b92733f8876f570fa16a3b644de34bc7279fbd2690

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page