pycln
A formatter for finding and removing unused import statements.
What it is and what it does
Pycln is a command-line formatter that scans Python source files to identify and remove unused import statements. It reads code using libcst for precise syntax tree analysis and can be configured via pyproject.toml or setup.cfg to apply project-specific rules like custom include/exclude patterns. The tool runs as a standalone CLI or as a Python module and integrates into CI/CD workflows and editor toolchains.
The package depends on typer for CLI argument handling, pyyaml for configuration parsing, pathspec for file matching, tomlkit for TOML manipulation, and libcst for abstract syntax tree operations. It targets modern Python versions (3.9 through 3.14) and is used by high-profile projects including Poetry, Rich, and pybind11.
Use it for:
- Clean up import sections in a Python project before committing or deploying code.
- Integrate into a pre-commit hook or CI pipeline to enforce import hygiene automatically.
- Refactor legacy codebases where imports have accumulated over time without cleanup.
- Configure project-wide import rules in pyproject.toml to standardize import handling across a team.
- Use as a linting step in build tools like cibuildwheel or Poetry to validate import statements.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Pycln finds and removes unused import statements from Python code, acting as a formatter that cleans up import sections automatically.
Yes. Pycln solves a real maintenance problem with low friction and permissive licensing. The aging maintenance status (297 days since last release) is a minor concern but not a blocker—the repository is active, no vulnerabilities are known, and the tool is trusted by established projects. Install it if import cleanup is a workflow need.
Install
pycln on PyPI
pip
pip install pyclnuv
uv add pyclnpoetry
poetry add pyclnInstalling pycln
Before you install
Low install friction with a pure-Python wheel distribution. Maintenance status is aging—last release was 297 days ago—but the repository remains active with a recent commit on 2026-01-13 and no archived status.
License in practice
MIT license is permissive; you can use, modify, and distribute pycln with minimal restrictions, making it suitable for both open-source and commercial projects.
Quickstart
pip install pycln
pycln /path/to/code
# Or as a module:
python3 -m pycln /path/to/code
Requires Python 3.9 or later.
Verify before relying
- Whether the -a/--all flag is necessary for typical use cases or only for edge cases.
- How pycln handles complex import patterns (star imports, conditional imports, type hints).
- Performance characteristics on large codebases or deeply nested directory structures.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4,>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — typer, pyyaml, pathspec, tomlkit, libcst |
| Maintenance | aging — 297 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 349,230/month — #7,336 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pycln-2.6.0-py3-none-any.whl
Keywords: formatter, linter, quality-assurance, tools, cli
Tags
More Utilities packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
charset-normalizerDetects and normalizes text encoding from…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
pluggyPluggy provides a plugin system that lets you…
permissive · top 100 on PyPI
PygmentsPygments is a syntax highlighter that colorizes…
permissive · top 100 on PyPI
sixSix provides utility functions to write Python…
permissive · top 100 on PyPI
autoflakeautoflake removes unused imports and unused…
permissive · top 5,000 on PyPI
clang-tidyPackages the clang-tidy C++ linter and related…
permissive · top 15,000 on PyPI
uncalledDetects unused functions in Python projects…
permissive · top 15,000 on PyPI
creosoteCreosote scans your Python project's source…
permissive · top 5,000 on PyPI
clang-formatPackages the clang-format code formatter as a…
permissive · top 5,000 on PyPI
pip-check-reqsAudits Python project imports against…
permissive · top 15,000 on PyPI
tclinttclint is a CLI linter, formatter, and language…
permissive · top 15,000 on PyPI
usortμsort sorts Python imports within detected…
permissive · top 5,000 on PyPI
deadcodeScans Python codebases to find and optionally…
agpl · top 15,000 on PyPI
pytest-unused-fixturesA pytest plugin that identifies and reports…
permissive · top 15,000 on PyPI