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

File metadata

File hashes

Hashes for philiprehberger_import_profiler-0.1.3.tar.gz
Algorithm Hash digest
SHA256 cc7595ba7a90c9919fa3d7a56545eda98930f9cb3ee38d12bcb4af17396ff5a6
MD5 644a004cd3f8df795af5b8000dc10595
BLAKE2b-256 9d4f0b743544195b579dd85c172e1592305331c0cf72b5c02e3ae3cf9c5eafcf

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for philiprehberger_import_profiler-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0855b46d28c2f7d1dfabc5cde7a544a4f5d76701504eb37d370c5b492867ecb9
MD5 e5a39533e5af7d7b442b9cd6d0a464da
BLAKE2b-256 aabd0b4f1475c77d47bc44ccc544e99bae4127608620b6107e39b0500a3636fc

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