Skip to main content

Show how long each Python import takes during startup

Project description

philiprehberger-import-profiler

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.0.tar.gz (4.2 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.0.tar.gz.

File metadata

File hashes

Hashes for philiprehberger_import_profiler-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ac2de83269b9e682c22b5538962033023c1e55f9d841685d2ccf188e8353a960
MD5 039c912645e43192b3e7e018d2488074
BLAKE2b-256 d720328c88271e9e82384b4f6d892f1d2ffb6170306d03747531548a120a98df

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_import_profiler-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7e42ad81e112468b33045624deaa1a9979e379af0270ea861be559b2d12714d0
MD5 0c0826473e26c214b2c3cbde9aa93cef
BLAKE2b-256 194bdc1ea8714dff6a646b5e8d7d788bf8d3d77a0eddbea7c9c60de30816ef6e

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