Skip to main content
Donate to the Python Software Foundation or Purchase a PyCharm License to Benefit the PSF! Donate Now

Explore dependencies of a Python package by parsing its imports.

Project description

Explore dependencies of a Python package by parsing its imports.

This might be useful for:

  • seeing how modules within a package depend on each other
  • seeing which built-in libraries are relied upon
  • analysis of 3rd-party dependencies
  • etc.


Explore dependencies of this project:

$ pkgdeps /path/to/pkgdeps
  - argparse.ArgumentParser
  - ast
  - collections.defaultdict
  - functools.reduce
  - os
  - os.path
  - sys


  • Only tested with Python 3 against Python 3 packages.
  • Doesn’t handle conditional imports; all conditional branches are inspected.
  • Outputs imported module members: from os.path import join creates a dependency on os.path.join, but we probably only want os.path for e.g. tsort output. However, internal dependencies are coarsened to the module level.


$ pip install pkgdeps


Various options are available to filter and format the output:

$ pkgdeps -h
usage: pkgdeps [-h] [-n <num>] [-m <num>] [-e <type> | -o <type>]
               [-f <format>]

Explore dependencies of a package by parsing its imports.

positional arguments:
  </path/to/package>    path to package root

optional arguments:
  -h, --help            show this help message and exit
  -n <num>, --package-module-name-segments <num>
                        truncate module names of inspected package to given
                        number of segments (and consolidate imports)
  -m <num>, --dependency-module-name-segments <num>
                        truncate module names of dependencies to given number
                        of segments (and deduplicate)
  -e <type>, --exclude <type>
                        exclude various kinds of dependencies from output
                        (builtin, 3rd-party, internal)
  -o <type>, --only <type>
                        include only dependencies of the given type (builtin,
                        3rd-party, internal)
  -f <format>, --format <format>
                        graph output format (tree, tsort)

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
pkgdeps-0.0.3-py2.py3-none-any.whl (7.4 kB) Copy SHA256 hash SHA256 Wheel py2.py3

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page