Pycln - Unused Import Cleaner
Pycln is a fast and efficient code formatter for finding and removing unused import statements in Python code. It helps to keep your codebase clean and reduce unnecessary dependencies. The current version is 2.6.0 and it maintains a relatively frequent release cadence, often aligning with Python version updates and bug fixes.
Warnings
- breaking Pycln dropped support for Python 3.8 in version 2.6.0. Users on Python 3.8 or older must use Pycln v2.5.0 or earlier.
- breaking Pycln dropped support for Python 3.7 in version 2.5.0. Users on Python 3.7 or older must use Pycln v2.4.0 or earlier.
- gotcha When running Pycln with Python 3.14 (or early development versions), versions prior to 2.6.0 might fail due to changes in Python's AST (specifically, `ast.Str` being removed).
- gotcha In versions prior to 2.5.0, Pycln could encounter 'missing pyproject.toml' errors when reading configuration, even if the file existed.
- gotcha Implicit imports (e.g., `from package import module` where `module` is not directly used but its side effects are needed) were sometimes misparsed and considered unused in Pycln versions prior to 2.1.6.
Install
-
pip install pycln
Imports
- main
from pycln.main import main
Quickstart
# To analyze current directory and remove unused imports: pycln . # To check for unused imports without modifying files: pycln --check . # To include specific files or directories: pycln my_module.py my_package/