Skip to main content

A framework-agnostic, process-safe, local performance timer for Python applications.

Project description

Performance Timing Module (tmng)

screenshot

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.1.2.tar.gz (17.0 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.1.2-py3-none-any.whl (19.4 kB view details)

Uploaded Python 3

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

Hashes for tmng-1.1.2.tar.gz
Algorithm Hash digest
SHA256 1ea041e6f85fb028a5e684a1668a71abd774f2a4c28bf64134720ef262552e7a
MD5 11ae92691f93f7da6d9376f23c75f380
BLAKE2b-256 59873693b3b2815cc4cfb2fb269ae9c613e434c89f78c5a35cd7b3f5b61b50d5

See more details on using hashes here.

Provenance

The following attestation bundles were made for tmng-1.1.2.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.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

Hashes for tmng-1.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b9101a8c790fc7b7856871352255de80043c6fdbc56274a8955716609286acfd
MD5 3fd076583243370a0e4c7017e0c27404
BLAKE2b-256 9387c6d6a76b784bf6ad4da020fb73efda58ee33e855d46139531dd8b34a2db9

See more details on using hashes here.

Provenance

The following attestation bundles were made for tmng-1.1.2-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