Skip to main content

A flexible clock implementation for real-time and backtesting scenarios

Project description

Chronopype

CI codecov Python 3.13+ PyPI License: MIT Docs

A flexible clock implementation for real-time and backtesting scenarios in Python. Chronopype provides a robust framework for managing time-based operations with support for both real-time processing and historical data backtesting.

Features

  • 🕒 Flexible Clock System: Support for both real-time and backtesting modes
  • 🔄 Processor Framework: Extensible system for implementing time-based operations with retry and timeout support
  • 🌐 Network-Aware: Built-in network processor with automatic reconnection and exponential backoff
  • Async Support: Full async/await support for efficient I/O operations
  • 📊 Performance Monitoring: Built-in execution time tracking, percentile statistics, and lagging processor detection
  • 🔒 Type Safe: Fully typed with MyPy strict mode
  • 🧪 Well Tested: Comprehensive test suite with high coverage

Installation

# Using pip
pip install chronopype

# Using uv
uv add chronopype

Quick Start

Here's a simple example of using chronopype:

import asyncio
import time

from chronopype import ClockConfig, ClockMode
from chronopype.clocks import RealtimeClock
from chronopype.processors import TickProcessor


class MyProcessor(TickProcessor):
    async def async_tick(self, timestamp: float) -> None:
        print(f"Processing at {timestamp}")


async def main():
    config = ClockConfig(
        clock_mode=ClockMode.REALTIME,
        start_time=time.time(),
        tick_size=1.0,  # 1 second ticks
    )

    async with RealtimeClock(config) as clock:
        clock.add_processor(MyProcessor())
        await clock.run_til(config.start_time + 10)


if __name__ == "__main__":
    asyncio.run(main())

Core Components

  • Clocks: Base implementations for time management

    • RealtimeClock: For real-time processing with drift compensation
    • BacktestClock: For deterministic historical data simulation
  • Processors: Framework for implementing time-based operations

    • TickProcessor: Base class for all processors
    • NetworkProcessor: Network-aware processor with automatic reconnection

Documentation

Full documentation is available at gianlucapagliara.github.io/chronopype.

Development

Chronopype uses uv for dependency management and packaging:

# Install dependencies
uv sync

# Run tests
uv run pytest

# Run type checks
uv run mypy chronopype

# Run linting
uv run ruff check .

# Run pre-commit hooks
uv run pre-commit run --all-files

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

chronopype-0.8.0.tar.gz (95.0 kB view details)

Uploaded Source

Built Distribution

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

chronopype-0.8.0-py3-none-any.whl (24.9 kB view details)

Uploaded Python 3

File details

Details for the file chronopype-0.8.0.tar.gz.

File metadata

  • Download URL: chronopype-0.8.0.tar.gz
  • Upload date:
  • Size: 95.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for chronopype-0.8.0.tar.gz
Algorithm Hash digest
SHA256 6b2aaa539858820a7bb7142033c5169cc6c12c06dff22e55f11812a5c48417a8
MD5 5cdcf215f9801dc43dc351d7e6747c9a
BLAKE2b-256 c1bdc49d9f38166b731fe8c66fbf1703e18284247ef0699445d0cb592c14c382

See more details on using hashes here.

File details

Details for the file chronopype-0.8.0-py3-none-any.whl.

File metadata

  • Download URL: chronopype-0.8.0-py3-none-any.whl
  • Upload date:
  • Size: 24.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.12 {"installer":{"name":"uv","version":"0.10.12","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for chronopype-0.8.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f7bede893da02047bae02727a6dc07573c575434bf529257b5b9df1454b5ba8e
MD5 ca237dc5d7e7e5da21900e785ff3e7ae
BLAKE2b-256 15a5b32da26b49755f409a5899e5a0b26524769fb412e7f295d956aebd8a43f9

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