Skip to main content

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

  1. Install the Package from PyPI:

    pip install tmng
    
  2. Enable the Timer: This only needs to be done once. It creates a config file in your user directory.

    timing enable
    
  3. Initialize the Database: Run this once in your project's root directory to create the timing_log.db file.

    timing init
    
  4. 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 ...
    
  5. Generate a Report: After your code has run, generate an interactive HTML dashboard.

    timing report
    

    This will generate timing_dashboard.html and 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 to true to 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tmng-1.0.0.tar.gz (16.8 kB view details)

Uploaded Source

Built Distribution

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

tmng-1.0.0-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for tmng-1.0.0.tar.gz
Algorithm Hash digest
SHA256 e0cb5368a719e658eff34f7ca6984746a0511aa45598f44a035035def21272a6
MD5 fc597698ed7ec7fc6f1251aa020c6b8e
BLAKE2b-256 fd769ec8f69e45b52b7341c6352d0e187231acd86f21609237645b7bd6eed0d2

See more details on using hashes here.

Provenance

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

Publisher: python-publish.yml on lguibr/timing

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

File details

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

File metadata

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

File hashes

Hashes for tmng-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 414e5ca2f5f5717ce8926e49c22ab148ec6e429e848e18841cc88760593590d4
MD5 f8c4bd87ef89f78475a393567acb15e0
BLAKE2b-256 21d55ea199e001b5a4a663fce73568e8efca63556d2f93886e2b3629f28a79db

See more details on using hashes here.

Provenance

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

Publisher: python-publish.yml on lguibr/timing

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