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.1.tar.gz (49.6 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.1-py3-none-any.whl (26.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

Hashes for pulse_core-0.1.1.tar.gz
Algorithm Hash digest
SHA256 24e45a93f4919a61b19a5768708f3888059ca1e366b9080689161be1f493ca4a
MD5 3cec5a1668dc4120face36c518b61646
BLAKE2b-256 0cb3212e0c5f589449918b27effe63f7c099c16f3628fb25d942f4f4c7b70cc7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pulse_core-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 638c1c4e3ba9c7355394cdbf9a3522c4b8847bdb3bd7e1f86e01672028e0d8cb
MD5 88845c7266ad606d90376172f6162c34
BLAKE2b-256 4bdaa9819e6ec9797fac87c853f1ed2222e9e3610e46dc40cb9bfcab303f1b08

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