Python

Python Import Analyser

Lists every import in a module, sorts them by origin, and counts how often each name is used.

Loading the tool…

Processing happens locally in your browser. What you paste or load is processed by this page and is not uploaded to a server. Nothing is stored unless you use a control that says it stores something, and you can clear anything this site has kept from the privacy page.

How to use this tool

  1. Paste the module, or load a .py file with the picker.
  2. Select Analyse the imports.
  3. Check any row with a use count of zero — it is a candidate for removal, not a certainty, since an import can exist for a side effect.
  4. Turn on the filter to see only the rows worth a second look.

What python import analyser does

Imports accumulate. A module that started with three grows to twenty, half of them left behind by code that moved elsewhere, and nothing in the language complains. This page reads the import statements — both forms, including aliases, multi-name imports and parenthesised lists spanning several lines — and counts how often each bound name appears in the rest of the file.

Two things get called out. A count of zero means the name is never referenced again, which usually means the import can go — usually, not always, because an import can exist for a side effect or to re-export a name, so the page suggests rather than asserts. A star import is flagged differently: it brings in an unknown set of names, so nothing here, or in your editor, or in a reader's head, can be sure what is in scope below it. Every import is also marked as standard library, relative, or third party, which is the split that tells you where your dependencies actually are.

Frequently asked questions

No, and the page says "check" rather than "remove" for that reason. An import can exist for a side effect — registering a plugin, applying a patch, populating a registry — and a module's __init__ often imports names purely to re-export them. What a zero does tell you reliably is that the name is not referenced anywhere else in this file, which is where the investigation starts.

Because nothing can check it. "from module import *" brings in a set of names that depends on the other module, possibly on its __all__, and possibly on what it imported in turn. Nothing here, nothing in your editor, and nobody reading the file can be sure what is in scope below that line. It is reported as its own kind of problem rather than counted as used or unused.

Yes. The source is read with a scanner that understands Python's strings and joins continuation lines, so a parenthesised import spanning five lines is read as one statement, and "import json as _json" is counted against the name _json rather than json. Relative imports are recognised as local, and every module is marked as standard library, relative, or third party.