A framework-agnostic, process-safe, local performance timer for Python applications.
Project description
Performance Timing Module (tmng)
A framework-agnostic, process-safe, local performance timer for Python applications, designed for easy development and debugging. It logs timing data to a local SQLite file, avoiding external dependencies and network latency.
This module is built for reliability, using Pydantic for rigorous data validation and serialization, ensuring that every timing event recorded is structured and correct.
Key Features
- Simple CLI: Manage the tool with intuitive commands like
timing enable,timing report. - Framework-Agnostic: Works with Django, Flask, FastAPI, or any Python script.
- Pydantic-Powered Validation: All timing events are validated against a strict schema.
- Process-Safe: Works flawlessly across multiple processes.
- Globally Switchable: Enable or disable via the CLI or an environment variable.
- Rich, Validated Context: Attach metadata (e.g.,
user_id,task_id) to your timing events.
Quickstart
-
Install the Package from PyPI:
pip install tmng
-
Enable the Timer: This only needs to be done once. It creates a config file in your user directory.
timing enable
-
Initialize the Database: Run this once in your project's root directory to create the
timing_log.dbfile.timing init -
Add Timing to Your Code: Use the decorators or context managers as needed.
from timing import time_block, time_function # Best for specific blocks with time_block("api_call", service="xero"): # ... timed code ... # Best for entire functions @time_function def send_weekly_emails(user_id): # ... timed function ...
-
Generate a Report: After your code has run, generate an interactive HTML dashboard.
timing reportThis will generate
timing_dashboard.htmland open it in your browser.
CLI Usage
The timing command is your main entry point for managing the tool.
| Command | Description |
|---|---|
timing status |
Check if the tool is enabled and see the event count. |
timing enable |
Globally enables the timing tool for your user. |
timing disable |
Globally disables the timing tool. |
timing init |
Creates the SQLite database file in the current directory. |
timing report |
Generates the interactive HTML report. |
timing report --output "perf.html" --no-open |
Customize report generation. |
Environment Variables
For servers or CI/CD, you can override the global config with environment variables:
TIMING_TOOL_ENABLED: Set totrueto enable the timer. This takes precedence over the CLI setting.TIMING_DB_PATH: Set the full path to your database file (e.g.,/var/data/my_app_timing.db).
Viewing the Data
You can still use any SQLite client to view the timing_log.db file or use the built-in report generator:
timing report
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 tmng-1.1.2.tar.gz.
File metadata
- Download URL: tmng-1.1.2.tar.gz
- Upload date:
- Size: 17.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1ea041e6f85fb028a5e684a1668a71abd774f2a4c28bf64134720ef262552e7a
|
|
| MD5 |
11ae92691f93f7da6d9376f23c75f380
|
|
| BLAKE2b-256 |
59873693b3b2815cc4cfb2fb269ae9c613e434c89f78c5a35cd7b3f5b61b50d5
|
Provenance
The following attestation bundles were made for tmng-1.1.2.tar.gz:
Publisher:
python-publish.yml on lguibr/timing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tmng-1.1.2.tar.gz -
Subject digest:
1ea041e6f85fb028a5e684a1668a71abd774f2a4c28bf64134720ef262552e7a - Sigstore transparency entry: 321210399
- Sigstore integration time:
-
Permalink:
lguibr/timing@03089e7bf4d9343091d13bd386bc6c2e46ef0bcd -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/lguibr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@03089e7bf4d9343091d13bd386bc6c2e46ef0bcd -
Trigger Event:
push
-
Statement type:
File details
Details for the file tmng-1.1.2-py3-none-any.whl.
File metadata
- Download URL: tmng-1.1.2-py3-none-any.whl
- Upload date:
- Size: 19.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9101a8c790fc7b7856871352255de80043c6fdbc56274a8955716609286acfd
|
|
| MD5 |
3fd076583243370a0e4c7017e0c27404
|
|
| BLAKE2b-256 |
9387c6d6a76b784bf6ad4da020fb73efda58ee33e855d46139531dd8b34a2db9
|
Provenance
The following attestation bundles were made for tmng-1.1.2-py3-none-any.whl:
Publisher:
python-publish.yml on lguibr/timing
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
tmng-1.1.2-py3-none-any.whl -
Subject digest:
b9101a8c790fc7b7856871352255de80043c6fdbc56274a8955716609286acfd - Sigstore transparency entry: 321210423
- Sigstore integration time:
-
Permalink:
lguibr/timing@03089e7bf4d9343091d13bd386bc6c2e46ef0bcd -
Branch / Tag:
refs/tags/v1.1.2 - Owner: https://github.com/lguibr
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@03089e7bf4d9343091d13bd386bc6c2e46ef0bcd -
Trigger Event:
push
-
Statement type: