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

Uploaded Python 3

File details

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

File metadata

  • Download URL: chronopype-0.8.1.tar.gz
  • Upload date:
  • Size: 99.5 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.1.tar.gz
Algorithm Hash digest
SHA256 5853f718b6c4a2f93b170a21d7587d8fa447c5db2b5979c777c643cecfcb5f07
MD5 eacae293382e749011f1c3c7580d787e
BLAKE2b-256 d5401dcb0f43715de9e941072975da0b56fbdfec630157227a8e6700b754e232

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chronopype-0.8.1-py3-none-any.whl
  • Upload date:
  • Size: 25.5 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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a81418180a7a1a23a3a4f92d4e2eb7d64569b309dd4c9c150029885a2208a31
MD5 ce8e6d3aef13c061b7cd5d1cb83f62d0
BLAKE2b-256 801e247ef76690886913e8f4b8050c38abb34011b8d723cb3e0af897c81da5e6

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