Thread-safe stopwatch for measuring elapsed time
Project description
ticko
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 statetime_elapsed: float- Total elapsed timetime_last_lap: float- Last lap duration
Methods:
start()- Start timingstop()- Stop and return elapsed timelap()- Record lap timereset()- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9e8e0717cb652ca02d70fd4d7a224e0c155369bd0b2c7c546f59147e4097c7a9
|
|
| MD5 |
32b187953105f8d5605ad9467d82d94e
|
|
| BLAKE2b-256 |
3de460ea2279e21234cff438bea5eae30ab64cd765dbcd0b9b7ba3b5a9557153
|
Provenance
The following attestation bundles were made for ticko-1.0.0.tar.gz:
Publisher:
publish.yml on NakuRei/ticko
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ticko-1.0.0.tar.gz -
Subject digest:
9e8e0717cb652ca02d70fd4d7a224e0c155369bd0b2c7c546f59147e4097c7a9 - Sigstore transparency entry: 622035444
- Sigstore integration time:
-
Permalink:
NakuRei/ticko@b053b60b205d0b7229af4c0559ee463483d0f817 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/NakuRei
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b053b60b205d0b7229af4c0559ee463483d0f817 -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f8622fc2b0fecb285182ff2cbf4aff8446b307e8255a28e18dfc06697819d2dd
|
|
| MD5 |
c38161e3c79042d3897e15a989dc6733
|
|
| BLAKE2b-256 |
f1858319db6d6d0008bfe02e29d9e697bf818480548169f133cf342af8a449db
|
Provenance
The following attestation bundles were made for ticko-1.0.0-py3-none-any.whl:
Publisher:
publish.yml on NakuRei/ticko
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ticko-1.0.0-py3-none-any.whl -
Subject digest:
f8622fc2b0fecb285182ff2cbf4aff8446b307e8255a28e18dfc06697819d2dd - Sigstore transparency entry: 622035445
- Sigstore integration time:
-
Permalink:
NakuRei/ticko@b053b60b205d0b7229af4c0559ee463483d0f817 -
Branch / Tag:
refs/tags/v1.0.0 - Owner: https://github.com/NakuRei
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@b053b60b205d0b7229af4c0559ee463483d0f817 -
Trigger Event:
push
-
Statement type: