Skip to main content

Python import time profiler.

Project description

importo

Python import time profiler.

Installing

importo requires Python 3.9 or higher to work.

To install run

$ pip install importo

Usage

importo can profile any Python module currently installed in your enviroment (virtual or otherwise).

$ importo datetime
cum     self    import
24219   957     runpy
13814   2181    contextlib
11998   2051    site
9016    2735    collections
7796    1934    os
4770    1689    encodings
3438    1328    pkgutil
3349    3349    _collections_abc
2878    661     importlib

By default, importo will only stay at the root module level, and order by cumulative time.

You can sort by cumulative time (time the import and all its child imports took), self (time spent on just this particular import, child imports excluded) and module name. You can also choose the depth of import to go into, much like du and other tools do as well as pipe into other unix commands.

For example

$ importo datetime -d 1 -m encodings | head
cum     self    import
2312    1068    encodings
649     649     encodings.aliases
400     400     encodings.latin_1
273     273     encodings.utf_8

instead of --match/-m you could also just pipe to grep and it would probably work just fine.

If you're looking for more statistical relevance in import times other than just a couple of runs, you can specify the number of iterations the profiler goes through.

$ importo datetime -i 400 -d 1 -m encodings
cum     self    import
2071    899     encodings
530     530     encodings.aliases
349     349     encodings.latin_1
332     332     encodings.cp437
246     246     encodings.utf_8

For multiple iterations, the p99 values are used as it's probably the most useful.

Testing

Tests are ran via tox to cover supported Python version. As such simply run

$ tox

from the root of the repository, whilst you have the required python versions accessible to tox.

Other

For more information on the available options run

$ importo -h

About

This tool was motivated by the fact that Python3.7 introduced a new feature to show cumulative module import times.

An explanation and use case for this new feature can be found in this blog entry from a CPython core dev.

This is a wrapper on top of python -X importtime. For small import trees I suggest using that tool first, it will probably suffice for your use case.

For actual production applications for my job, I've found that this tools helps me in narrowing down culprits and statistically tracking improvements.

Notes

I've noticed that the sum of self times doesn't fully add to the cumulative value of the root module. I don't yet know why this is the case.

Wishlist

  1. Move project direction to also support detection of import cycles.

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

importo-0.2.1.tar.gz (12.8 kB view details)

Uploaded Source

Built Distribution

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

importo-0.2.1-py3-none-any.whl (5.1 kB view details)

Uploaded Python 3

File details

Details for the file importo-0.2.1.tar.gz.

File metadata

  • Download URL: importo-0.2.1.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for importo-0.2.1.tar.gz
Algorithm Hash digest
SHA256 a63cf35f41f09f8887125a2996ac74d78740c967ae6913ce30e2507605ababa5
MD5 16ffa59be95b543a5c5ac42d7c6df9a9
BLAKE2b-256 a7e2294bc64bc102d03caf9275accc34c583f9e7e67b2f264350b689b8b6e3b7

See more details on using hashes here.

File details

Details for the file importo-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: importo-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 5.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.5

File hashes

Hashes for importo-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fb1b01235dda9c363495099a6976964097e1cb5204f26328f9b3a087a052f210
MD5 cf103c3460273b927d49a4317de670ad
BLAKE2b-256 bd351723b51e50ebb2deef330af509e73118e6d20d3561b5cc63309154957b53

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