Skip to content

mgedmin/findimports

Repository files navigation

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

About

Static analysis of Python import statements

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 7