Skip to main content

Pure computation library: strategy engines, indicators, and shared types 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.3.tar.gz (41.5 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.3-py3-none-any.whl (22.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pulse_core-0.1.3.tar.gz
  • Upload date:
  • Size: 41.5 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.3.tar.gz
Algorithm Hash digest
SHA256 230c4357c99f732d0e32efe9c5e0cfbfccc457eeccbc2632ff68dcfa68d985e7
MD5 870bf52f2d8fd2e964ed77dd895ac7a6
BLAKE2b-256 488f6bedfa69251bfcde983326bfb61c6befa75336e316524a72cc9d875493c9

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pulse_core-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 22.2 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0f8195ce5bde37ab5fcb752686b146097465a057df3557a6d61d2a5e290b2400
MD5 184a46531ae661a647beb0cda84f3427
BLAKE2b-256 9f809e78e84e14e1879c8e53deecc48ae6e485f9fefe9a92555f980824b06934

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