Skip to main content

Show how long each Python import takes during startup

Project description

philiprehberger-import-profiler

Tests PyPI version License

Show how long each Python import takes during startup.

Installation

pip install philiprehberger-import-profiler

Usage

from philiprehberger_import_profiler import profile_imports

report = profile_imports("my_package")

# Slowest imports
for entry in report.slowest(10):
    print(f"{entry.name}: {entry.duration_ms:.1f}ms")

# Tree view
report.print_tree(threshold_ms=5.0)
# └── my_package (124.5ms)
#     ├── requests (45.2ms)
#     │   └── urllib3 (22.1ms)
#     └── numpy (62.0ms)

# Summary
print(f"Total: {report.total_ms:.1f}ms, Modules: {report.module_count}")

# Export
data = report.to_dict()

API

  • profile_imports(module_name) — Profile all imports, returns ImportReport
  • report.slowest(n) — Top N slowest imports
  • report.print_tree(threshold_ms=0) — Print indented tree
  • report.total_ms — Total import time
  • report.to_dict() — Export as list of dicts

Development

pip install -e .
python -m pytest tests/ -v

License

MIT

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

philiprehberger_import_profiler-0.1.5.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

File details

Details for the file philiprehberger_import_profiler-0.1.5.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_import_profiler-0.1.5.tar.gz
Algorithm Hash digest
SHA256 083475bb328a77e6c3223f3376b91fa5a0521e8442392a8e1559af24f2e98999
MD5 22e288492f919a7d22dc33e7e0f13a8a
BLAKE2b-256 1292bed6351cf3b58b1072952714e27edeb6ef64edb74cecd1ccc7cbb6d656bc

See more details on using hashes here.

File details

Details for the file philiprehberger_import_profiler-0.1.5-py3-none-any.whl.

File metadata

File hashes

Hashes for philiprehberger_import_profiler-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 e633d957b8d680491032fdae48c4bf883b7fca636eecf9b047b662341679a35d
MD5 90818e72d14de131a7b2890f45ddb2b0
BLAKE2b-256 9854c24e60f5a2e7ec846bbd3ce9e9334da8ba8a3c1b8f2fe077fc762f69ea79

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