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.7.3.tar.gz (91.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.7.3-py3-none-any.whl (21.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: chronopype-0.7.3.tar.gz
  • Upload date:
  • Size: 91.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.7.3.tar.gz
Algorithm Hash digest
SHA256 8eacb36bc67a8ade3f22b92c30432cc8473e81acd2db5460db84b3af4b5934f5
MD5 c53873ab057a5a8983e31d72700feb3b
BLAKE2b-256 7ea4a5e324c09684e0c7020e4d9d05d6c06c098b3f781eabd9f461d8e1d13c8e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: chronopype-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 21.2 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.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 6692234c934860f8efe6125df0f1c933a6e64f236f0ee6474fd76f367e54ebbb
MD5 140ec2e59421b333a56c9859da5ea5f4
BLAKE2b-256 568e4ccad941c6993d2510fcd7311607323fbf1e595dd5c037db276c0289fef4

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