Pocketwatch
Pocketwatch provides a simple stopwatch for timing any block of Python code. It can display desktop notifications, play a chime after long runs, and optionally collect profiling statistics.
Installation
pip install pocketwatch
Basic Usage
from pocketwatch import Pocketwatch
with Pocketwatch("load data"):
load_data()
The context manager prints the elapsed time when the block finishes. Pass a
logging.Logger if you also want the output sent to a log. Notifications and
sound are disabled unless explicitly requested.
with Pocketwatch(
"big task",
notify=True, # show a pop-up
notify_after=5.0, # minimum duration before popup
sound=True, # play ding.wav
sound_after=60.0, # minimum duration for sound
):
run_big_task()
You can capture intermediate checkpoints using mark() (or its alias
log()):
with Pocketwatch("steps") as pw:
load()
pw.mark("loaded data")
transform()
pw.log("transformed")
To enable cProfile integration, pass profile=True. By default the raw stats
are written to profile_output.prof; set profile_output_path=None to skip
writing the file. Call end(return_stats=True) to retrieve a
pstats.Stats instance.
with Pocketwatch(profile=True) as pw:
crunch_numbers()
stats = pw.end(return_stats=True)
Decorator Shortcut
A lightweight decorator mirrors the context manager. It uses the function name as the message label and prints the elapsed time. Provide a logger argument to forward output to your own logging setup.
from pocketwatch.decorators import stopwatch
@stopwatch
def do_work():
...
Custom options may be supplied when decorating:
@stopwatch(sound=True, notify=False)
def background_job():
...
Features
- Drop-in context manager for timing code blocks
- Desktop notifications via notifypy
- Optional sound playback with bundled audio files
- Incremental mode to suppress output for short runs
- Optional logging to a custom logger
- Checkpointing with
mark()orlog() - cProfile support with stats returned on request
- Works with Python 3.9+
- Licensed under the MIT license
Metadata
Release files for pocketwatch 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pocketwatch-0.1.2.tar.gz | 999.6 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pocketwatch-0.1.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 2.0 MB
Release files / pocketwatch-0.1.2.tar.gz
| Download URL | pocketwatch-0.1.2.tar.gz |
|---|---|
| Size | 999.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5eb1ee38b049a2628ea0cce49c881e6de5ce8ee7eee2f94ea8aeb200950dcd1c
|
|
BLAKE2b-256 checksum How to use checksums |
3be67fdc0d97f554844f1d8ee03063c8124ba90267133593f67a6a0905cdbe1b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.5
|
Release files / pocketwatch-0.1.2-py3-none-any.whl
| Download URL | pocketwatch-0.1.2-py3-none-any.whl |
|---|---|
| Size | 996.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e87a6eda787c9c12a5698eedcc43e0fc54d963bfe324307d22edf97d946c4ef5
|
|
BLAKE2b-256 checksum How to use checksums |
92f4a95a38dcf7d8fe28d2dfa97d81dc176a010ba4a732397e519f625b8412bc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.5
|
Security for pocketwatch 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.