Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/takluyver/importtracer

Track Python imports
https://github.com/takluyver/importtracer

Last synced: 4 days ago
JSON representation

Track Python imports

Awesome Lists containing this project

README

        

Trace Python imports

Command line usage::

python3 importtracer.py [--csv file.csv] [--networkx] [-x pkg [-x ...]] module

This will import ``module``, tracking everything that gets imported. Passing
``--csv`` will dump the results as a CSV file. ``--networkx`` will draw the
graph of imports using `NetworkX `_. ``-x`` options
will exclude packages from the reporting by prefix (the data is still collected,
but not displayed).

Python usage:

.. code:: python

import importtracer

with importtracer.track(excludes=['numpy']) as it:
import matplotlib

# The imports made, as (modulename, importedby, time), filtering exclusions
it.filtered_links

# Save these as CSV:
it.dump_csv('file.csv')

# Make a NetworkX graph
g = it.dump_nx_graph()
# Draw the graph
networkx.draw(g); plt.show()