Importchecker
What is importchecker?
Importchecker is a command line utility to find unused imports in Python modules.
Its output is “grep-like” (and thus “emacs-friendly”), reporting both the module’s filenames and line numbers where names are imported that are not actually used in the module.
Importchecker will not modify any of the source files. Whether the import needs to be removed is left to the judgement of the developer.
Installation
The importchecker command line utility can be installed using the pip:
$ pip install importchecker
The command can then be invoked with either a directory or a Python file:
$ importchecker /path/to/a/source/tree $ importchecker /path/to/a/source/tree/module.py
Buildout
Projects that make use of zc.buildout for development might find the following buildout.cfg. snippet useful for using the importchecker on the developed codebase:
[buildout]
...
parts = importchecker ...
...
[importchecker]
recipe = zc.recipe.egg
eggs = importchecker
arguments = "${buildout:directory}/src"
Known issues
One source tree path argument at the time can be passed to the command line utility.
Command line argument parsing is rather naïve.
Changes
3.0 (2024-02-16)
Add support for Python 3.7, 3.8, 3.9, 3.10, 3.11.
Drop support for Python 2.7, 3.4, 3.5, 3.6.
2.0 (2018-02-22)
The tests indicate importchecker still works for Python 2, but since the AST structures can differ between Python 2 and Python 3, no support is formally claimed.
1.2 (2018-02-21)
Start on test coverage.
Claim support for Python 2.7, drop claims for earlier versions.
1.1 (2012-01-09)
Applied provided by wosc enabling running the import checker on individual python modules not just directories.
Report the absolute path for modules when needed, relative paths (relative to the current working directory, that is) when possible.
1.0 (2008-05-06)
Initial packaging
Make the importchecker work on python 2.5
Credits
Martijn Faassen (original developer)
Jan-Wijbrand Kolman (packaging)
Philipp von Weitershausen
various comitters on svn.zope.org.
Download
Release files for importchecker 3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| importchecker-3.0.tar.gz | 11.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| importchecker-3.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 21.3 kB
Release files / importchecker-3.0.tar.gz
| Download URL | importchecker-3.0.tar.gz |
|---|---|
| Size | 11.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
ce4fd5bd697d4b36bf2816a6c3675e66b620abed550f60b89edf9e2b99055c57
|
|
BLAKE2b-256 checksum How to use checksums |
2904cd8c2179797ddbcec15ca90d02d46a54316bb57fb914f931e114ca19111b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|
Release files / importchecker-3.0-py3-none-any.whl
| Download URL | importchecker-3.0-py3-none-any.whl |
|---|---|
| Size | 10.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8eba2f85ffef681a65c678f6877c41e1f836cfcbd7df0a4132dcef0cf3b7a6f3
|
|
BLAKE2b-256 checksum How to use checksums |
706bf4f8df231745d1d28183ee9f00ff115426b07a1aaeac6e0977f7f5efe084
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.11.8
|