Skip to main content

Module Graph

Show python modules dependency graph and static memory usage.

Install

First you need graphviz installed in your system.

  • Mac:

    brew install graphviz
    
  • Ubuntu:

    sudo apt-get update
    sudo apt-get install graphviz libgraphviz-dev pkg-config
    

Then:

pip install 'module-graph[all]'

Usage

Analysis current installed modules

Travel all modules and generate graph data:

python -m module_graph.run_traveler

Command reference:

usage: run_traveler.py [-h] [--modules MODULES] [--ignore IGNORE]

Module Graph Traveler

optional arguments:
  -h, --help         show this help message and exit
  --modules MODULES  top level modules to check, default all modules
  --ignore IGNORE    ignore modules (shell patterns)

Analysis modules used by application

Warning: the hooker will do crazy patch to sys module, your application may be slower or crash!

Setup hooker as early as possible in application.

import module_graph

if __name__ == "__main__":
    memory_hooker = module_graph.setup_hooker(
        save_to='data/module_graph.json', verbose=True)

Run your aplication for a while, then stop it. The hooker will generate data for all modules used by application.

Render graph

Use module-graph command to render graph, for example:

module-graph --input-filepath data/module_graph.json

Command reference:

usage: module-graph [-h] [--modules-filepath MODULES_FILEPATH]
                    [--input-filepath INPUT_FILEPATH]
                    [--output-filepath OUTPUT_FILEPATH]
                    [--threshold THRESHOLD]

Module Graph Render

optional arguments:
  -h, --help            show this help message and exit
  --modules-filepath MODULES_FILEPATH
                        modules to render, default all modules
  --input-filepath INPUT_FILEPATH
                        the module graph data generated by hooker (json file)
  --output-filepath OUTPUT_FILEPATH
                        render output PDF filepath
  --threshold THRESHOLD
                        donot show module which memory usage < threshold (MB)

How it work

It patch sys.meta_path, sys.modules and all module loaders, then record memory before and after module import.

License

This package is distributed under the MIT license.

Metadata

Release files for module-graph 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for module-graph 0.0.1
File Size Uploaded Provenance
module-graph-0.0.1.tar.gz 8.6 kB Without provenance Details

Release files / module-graph-0.0.1.tar.gz

Download URL module-graph-0.0.1.tar.gz
Size 8.6 kB
Tags Source
SHA-256 checksum
How to use checksums
8d28b8ca24a7f83f8b4388b2fabfb17802e6ac489e33488b463dc67e168f8338
BLAKE2b-256 checksum
How to use checksums
1e7f5342a99e5dfaf0a5b9db1239878398461195ca34906125cb5a7c54b9981f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.6.2 requests-toolbelt/0.9.1 tqdm/4.36.1 CPython/3.6.9

Security for module-graph 0.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.0.1 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page