Skip to main content

FindImports

FindImports extracts Python module dependencies by parsing source files. It can report names that are imported but not used, and it can generate module import graphs in ASCII or graphviz or JSON formats.

A distinguishing feature of findimports used to be that it could parse doctest code inside docstrings.

Note that not all cases are handled correctly, especially if you use ‘import foo.bar.baz’, or rely on PEP 420 implicit namespace packages.

If you need to find unused imports in your codebase, I recommend flake8 instead – it’s better maintained and more reliable. For import graphs consider pydeps.

Installation

Use your favorite Python command-line tool installer such as pipx or uv. Or run it without installing with

uvx findimports --help

Module dependency graphs

On larger projects the module graphs tend to be an unreadable mess. You can make them clearer by post-processing the graph with tred to remove graph edges representing direct dependencies to modules that you’re already transitively depending on:

uvx findimports -N -q src -d | tred | xdot -

tred is part of graphviz. xdot is a nice interactive graphviz viewer.

Misc

Home page: https://github.com/mgedmin/findimports

Licence: MIT (https://mit-license.org/)

buildstatus coverage

Changes

3.0.0 (2025-12-08)

  • -t/--tred to compute a transitive reduction of the import graph. Somewhat experimental.

  • Bugfix: names getting imported from a package’s foo/__init__.py` were not being correctly tracked; they instead were treated as imports from an external package ‘foo’, while ‘foo.__init__’ was shown to be with no incoming edges.

Backwards incompatible changes: modules named __init__ are now treated as packages, so instead of foo.__init__ in the output you’ll see just foo.

2.8.0 (2025-12-06)

  • -l/--levels now works even without using -p. This lets you collapse subpackages while still seeing modules inside the top-level package.

2.7.0 (2025-11-14)

  • Add support for Python 3.14.

  • Drop support for Python 3.8 and 3.9.

  • Add --quiet/-q to suppress “could not find some.module” warnings.

  • Add --json/-j to produce JSON output.

  • Support glob patterns in --ignore/-I. Make the default ignore pattern .*.

Backwards incompatible changes: venv is no longer ignored by default. The Python community has settled on .venv as the default directory name for a project-local virtual environment, which is now ignored by the new default ignore pattern.

2.6.0 (2025-06-02)

  • Drop support for Python 3.7.

  • Add --csv/-C output format: pull request 32.

  • Add --search-import/-s command-line option to filter imports by substring: pull request 33.

2.5.2 (2024-11-27)

  • Bugfix: findimports was treating all imports as relative, just like in the good old Python 2 days. Oops.

  • When reporting that it couldn’t find the source for an imported module, findimports will now mention the line number that contained the import statement.

2.5.1 (2024-10-09)

  • Add support for Python 3.13.

2.5.0 (2024-05-30)

2.4.0 (2024-02-01)

  • Add support for Python 3.12.

  • Change license from GPL to MIT. See issue 27.

  • Add --package-externals/-pE to simplify the module graph.

  • Add --rmprefix PREFIX/-R PREFIX to remove a package prefix from displayed names.

  • Add --depth N/-D N to ignore import statements nested too deep in the syntax tree (e.g. in functions or if statements).

2.3.0 (2022-10-27)

  • Rewrote command-line parsing to use argparse. Options that select an action (--imports/--dot/--names/--unused) now conflict instead of all but the last one being ignored. See pull request #20.

  • Add support for Python 3.11.

  • Drop support for Python 3.6.

2.2.0 (2021-12-16)

  • Add support for Python 3.10.

  • Add --ignore-stdlib flag to ignore modules from the Python standard library.

2.1.0 (2021-05-16)

  • Add --ignore flag to ignore files and directories, it can be used multiple times. See pull request #14.

2.0.0 (2021-05-09)

  • Add support for Python 3.9.

  • Drop support for Python 3.5 and 2.7.

  • Fix a bug where the encoding of Python files was not determined in the same way as by Python itself. See issue 15. This requires the use of tokenize.open which is not in Python 2.7.

1.5.2 (2019-10-31)

  • Add support for Python 3.8.

  • Fix a bug where a package/module with a name that is a prefix of another package/module might accidentally be used instead of the other one (e.g. py instead of pylab). See issue 10.

1.5.1 (2019-04-23)

  • Drop support for Python 3.4.

1.5.0 (2019-03-18)

  • Support Python 3.6 and 3.7.

  • Drop support for Python 2.6 and 3.3.

  • Suppress duplicate import warnings if the line in question has a comment.

1.4.1 (2016-09-28)

  • Replace getopt with optparse. This changes the --help message as a side effect (#4).

1.4.0 (2015-06-04)

  • Python 3 support (3.3 and newer).

  • Use ast instead of compiler (#1).

1.3.2 (2015-04-13)

  • Fix “cannot find datetime” on Ubuntu 14.04 LTS (#3).

  • 100% test coverage.

1.3.1 (2014-04-16)

  • Added support for relative imports (e.g. from .. import foo).

1.3.0 (2013-04-10)

  • Moved to Github.

  • Drop Python 2.4 and 2.5 support.

  • Handle unicode docstrings with doctests.

1.2.14 (2012-02-12)

1.2.13 (2011-04-18)

  • Suppress “not a zipfile” warnings about *.egg-info files listed in sys.path.

1.2.12 (2011-04-08)

  • Handle zipfile errors when there are plain files that are not zip files on sys.path.

1.2.11 (2011-03-30)

  • Fix ‘could not find cPickle’ errors on Python 2.6 and newer.

1.2.10 (2010-02-05)

  • Ignore ‘from __future__ import …’.

1.2.9 (2009-07-07)

  • Fixed broken and uninstallable source distribution by adding a MANIFEST.in.

1.2.8 (2009-07-07)

  • Is able to find modules inside zip files (e.g. eggs).

  • Fixed deprecation warning on Python 2.6.

Release files for findimports 3.0.0

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

Source distribution (sdist)

Source distribution for findimports 3.0.0
File Size Uploaded
findimports-3.0.0.tar.gz 30.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for findimports 3.0.0
File Interpreter ABI Platform
findimports-3.0.0-py3-none-any.whl Python 3 none any Details

Total release size:47.3 kB

Release files / findimports-3.0.0.tar.gz

Download URL findimports-3.0.0.tar.gz
Size 30.9 kB
Tags Source
SHA-256 checksum
How to use checksums
91c8b9962bccfc856562033089fb63ea41186419f0a3500e97449e85f301f615
BLAKE2b-256 checksum
How to use checksums
9d5de4c476ec4b6d6bf212a9e0124c0f9ec6d5c097e10963df1c8829a73de7de
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / findimports-3.0.0-py3-none-any.whl

Download URL findimports-3.0.0-py3-none-any.whl
Size 16.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
29a8276a1f1363d2cec7fe901c43072b392b330bcf9614b160f9fd5348c97ceb
BLAKE2b-256 checksum
How to use checksums
dab680337c8592183c41afbb802f5fdb516dc0e24aa2c09958ddafe46dd27a38
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

3.0.0 This release

2 release files

2.8.0

2 release files

2.7.0

2 release files

2.6.0

2 release files

2.5.2

2 release files

2.5.1

2 release files

2.5.0

2 release files

2.4.0

2 release files

2.3.0

2 release files

2.2.0

2 release files

2.1.0

2 release files

2.0.0

2 release files

1.5.2

2 release files

1.5.1

2 release files

1.5.0

2 release files

1.4.1

2 release files

1.4.0

2 release files

1.3.2

1 release file

1.3.1

1 release file

1.3.0

1 release file

1.2.14

1 release file

1.2.13

1 release file

1.2.12

1 release file

1.2.11

1 release file

1.2.10

1 release file

1.2.9

1 release file

1.2.8

1 release file

1.2.7

1 release file

1.2.6

1 release file

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