Skip to main content

Lightweight profiler for Python: track function calls, runtimes, and dead code with minimal overhead.

Project description

Modulens Python SDK

Lightweight profiler for Python applications: track function calls, runtimes, and dead code with minimal overhead. Works with any Python framework (Flask, Django, FastAPI, Celery, or plain Python).

Quick start

import modulens

modulens.start(include=["app"])  # only track modules whose name starts with "app"
# ... run your app ...
modulens.flush()  # optional: flush now (otherwise auto-flush on interval and at exit)

Configuration

Include / exclude / sampling

  • include — List of module name prefixes to track (e.g. ["app"]). Recommended to avoid stdlib/third‑party noise.
  • exclude — Additional prefixes to ignore (default includes flask, werkzeug, gunicorn, logging).
  • sample_rate — 0.0–1.0; 1.0 = 100% of calls (default), lower for high‑traffic apps.

Environment variables

Variable Description Default
MODULENS_FLUSH_INTERVAL Seconds between auto-flushes 30
MODULENS_OUTPUT Where to send data: file, http, or both file
MODULENS_API_URL Modulens ingest API base URL (e.g. https://api.modulens.io)
MODULENS_API_KEY Project API key (from Modulens dashboard)
MODULENS_PROJECT_ID Project ID (slug) from dashboard
MODULENS_ORG_ID Organization ID (number)
MODULENS_ENVIRONMENT Environment name (e.g. production, staging) production

E2E: send data to the Modulens dashboard

  1. In the Modulens dashboard, create or open a project and copy Project ID and Org ID.

  2. Generate an API key for the project (e.g. Project Settings).

  3. Set in your environment (or .env):

    MODULENS_API_URL=https://your-backend.example.com
    MODULENS_API_KEY=ml_xxxx
    MODULENS_PROJECT_ID=your-project-slug
    MODULENS_ORG_ID=1
    MODULENS_ENVIRONMENT=production
    MODULENS_OUTPUT=http
    
  4. Run your app. The SDK will POST snapshots to the ingest API on each flush (interval + at exit). Data appears in the dashboard.

Use MODULENS_OUTPUT=both to keep writing to modulens_output/runtime_report.json and send to the API.

Local-only (file output)

If you do not set MODULENS_API_URL / MODULENS_API_KEY / MODULENS_PROJECT_ID, the SDK only writes to:

  • modulens_output/runtime_report.json — Array of snapshots (timestamp, called_functions, dead_functions).

API

  • modulens.start(include=None, exclude=None, sample_rate=1.0) — Start profiling. Registers atexit flush and a background flush loop.
  • modulens.flush(report=True) — Flush current stats now (to file and/or ingest). Resets in-memory counts so the next flush is for the next interval.
  • modulens.stop(report=True) — Stop profiling: final flush, stop the flush loop, remove the profiler from the interpreter, and unregister the atexit handler. Safe to call multiple times; no-op if not started. You can call start() again after stop().

Requirements

  • Python 3.8+
  • No framework lock-in; works with Flask, Django, FastAPI, Celery, or any Python app.

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

modulens-0.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

modulens-0.1.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file modulens-0.1.1.tar.gz.

File metadata

  • Download URL: modulens-0.1.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for modulens-0.1.1.tar.gz
Algorithm Hash digest
SHA256 cd1af9f06670c8ed57d93e7f2d5b88aababf88ee1496b1e57fc0b755f1a7818a
MD5 7904d64fd5385db914bf7f2edf27f5f3
BLAKE2b-256 cece039ad0d5cd0a99d2d150f700cea1fab0156c6b65a770e2f8eddbcda95f52

See more details on using hashes here.

File details

Details for the file modulens-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: modulens-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for modulens-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 abdf17f703ef168cfdc292747c8ae36c9bd7e4bfdf080678542c5d80a9130e60
MD5 78d82359c32d5ba3d078b5ad0f3d7d8e
BLAKE2b-256 f57a63d5b2a41f68e696ef737e8affcc3eb614a34f25ccc87ea3090b72665cfb

See more details on using hashes here.

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