skillfed

pycln

A formatter for finding and removing unused import statements.

pycln v2.6.0 349.2K downloads/30d#7,336 on PyPI314
Permissive license MIT AGING released

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 pycln

uv

uv add pycln

poetry

poetry add pycln

Installing 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

License :: OSI Approved :: MIT LicenseProgramming Language :: PythonProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.9Topic :: Utilities

Tags

remove unused imports pythonimport cleanup formatterunused import detectionpython import linterclean up import statementsimport statement formatterunused imports remover
import-cleanupcode-qualitycli-tool

More Utilities packages