Skip to main content

Thread-safe stopwatch for measuring elapsed time

Project description

ticko

CI codecov Python 3.10+ License: MIT

A modern, thread-safe stopwatch library for Python.

Why ticko?

  • Thread-safe by design - Use confidently in concurrent applications
  • Type-safe - Full type hints for excellent IDE support
  • Zero dependencies - Pure Python, no external requirements
  • Flexible API - Context managers, decorators, or manual control
  • Production-ready - Comprehensive test coverage

Installation

pip install ticko

Quick Start

from ticko import StopWatch

# Basic usage
with StopWatch() as sw:
    # Your code here
    pass

print(f"Elapsed: {sw.time_elapsed:.2f}s")
from ticko import stopwatch

# Decorator for function timing
@stopwatch
def process_data():
    # Your code here
    pass

process_data()  # Automatically prints execution time

Core Features

Manual Control

sw = StopWatch()
sw.start()
# ... your code ...
elapsed = sw.stop()

Lap Timing

sw = StopWatch()
sw.start()

# Record multiple laps
lap1 = sw.lap()
lap2 = sw.lap()

elapsed =sw.stop()

Custom Callbacks

def log_time(sw: StopWatch):
    logger.info(f"Execution took {sw.time_elapsed:.3f}s")

@stopwatch(exit_callback=log_time)
def my_function():
    pass

Thread Safety

from concurrent.futures import ThreadPoolExecutor

sw = StopWatch()
sw.start()

# Multiple threads can safely share one StopWatch
with ThreadPoolExecutor(max_workers=5) as executor:
    futures = [executor.submit(sw.lap) for _ in range(10)]

elapsed =sw.stop()

For more examples, see the examples/ directory.

API Overview

StopWatch

Properties:

  • is_running: bool - Current state
  • time_elapsed: float - Total elapsed time
  • time_last_lap: float - Last lap duration

Methods:

  • start() - Start timing
  • stop() - Stop and return elapsed time
  • lap() - Record lap time
  • reset() - Reset to initial state

@stopwatch

Decorator for automatic function timing with optional custom callbacks.

Development

# Install with dev dependencies
uv sync --dev

# Run tests
pytest tests/

# Run tests with coverage report
pytest tests -v --cov=src --cov-report=term-missing --cov-report=xml:cov.xml

# Type checking
mypy .

# Lint checking
ruff check

# Format checking
ruff format --check --diff

License

MIT License - Copyright (c) 2025 NakuRei

Contributing

Contributions welcome! Feel free to open issues or submit pull requests.

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

ticko-1.0.0.tar.gz (6.0 kB view details)

Uploaded Source

Built Distribution

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

ticko-1.0.0-py3-none-any.whl (7.1 kB view details)

Uploaded Python 3

File details

Details for the file ticko-1.0.0.tar.gz.

File metadata

  • Download URL: ticko-1.0.0.tar.gz
  • Upload date:
  • Size: 6.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ticko-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9e8e0717cb652ca02d70fd4d7a224e0c155369bd0b2c7c546f59147e4097c7a9
MD5 32b187953105f8d5605ad9467d82d94e
BLAKE2b-256 3de460ea2279e21234cff438bea5eae30ab64cd765dbcd0b9b7ba3b5a9557153

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticko-1.0.0.tar.gz:

Publisher: publish.yml on NakuRei/ticko

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file ticko-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: ticko-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 7.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for ticko-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f8622fc2b0fecb285182ff2cbf4aff8446b307e8255a28e18dfc06697819d2dd
MD5 c38161e3c79042d3897e15a989dc6733
BLAKE2b-256 f1858319db6d6d0008bfe02e29d9e697bf818480548169f133cf342af8a449db

See more details on using hashes here.

Provenance

The following attestation bundles were made for ticko-1.0.0-py3-none-any.whl:

Publisher: publish.yml on NakuRei/ticko

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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