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

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.2.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.2.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_import_profiler-0.1.2.tar.gz
Algorithm Hash digest
SHA256 3fd87b8d2eaf1730e549227dd9825bdaaaccf67c1d095ed668ff22e751665e47
MD5 27fc9071928132ad2753f0edd7094b28
BLAKE2b-256 66e3588b5396d3e5bca5ab7b3899f4c1c620b3291ee245dda4751b18430afcca

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_import_profiler-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8f7f57ef10bb4bbe5ef422619809631083f3fa92d40ad817462408eea6c8f2ce
MD5 a47b3194d9903e593844289dd357ff01
BLAKE2b-256 1ab64878d864482583496d54bd430020295a0c1c1b69aafe9b86a00fba5985b8

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