Python Code Quality Tools
Most tools can/should be configured to run automatically, except the once marked with a ⚒, which I would consider more suitable for ad-hoc usage. My personal favorite tools are marked with ★.
Formatting
- ★ black: Uncompromising Python code formatter. By using it, you agree to cede control over minutiae of hand-formatting.
- isort: A Python utility / library to sort imports alphabetically, and automatically separated into sections and by type.
- ★ mdformat-gfm: mdformat-plugin that changes the target specification to GitHub Flavored Markdown (GFM).
- pydocstyle: Static analysis tool for checking compliance with Python docstring conventions.
- pyupgrade: Update parts of the code using more modern syntax.
- autoflake: remove unused variables and imports.
Type checking
- ★ mypy: Type checks Python Code. It can catch many programming errors by analyzing your prqogram, without actually having to run it
- pyright: Fast type checker by Microsoft, meant for large Python source bases.
Linting
- ★ ruff Super fast linter which implements most rules from pylint, pyflake, pydocstyle and more. It also does some formatting, e.g. replaces isort, pyupdate and removes unused imports.
- pylint: Static code analysis tool which looks for programming errors, helps enforcing a coding standard, sniffs for code smells and offers simple refactoring suggestions. Lot’s of extensions available!
- pyflakes: Pyflakes analyzes programs and detects various errors. It works by parsing the source file, not importing it, so it is safe to use on modules with side effects. It’s also much faster.
Reduce code complexity
- ★ ⚒ pydeps: Python module dependency visualization.
- ★ ⚒ vulture: Finds unused code in Python programs.
- ★ ⚒ radon: Tool that computes various metrics from the source code.
- ★ ⚒ wily: Uses git to go through each revision (commit) in a branch a,nd reports complexity and code-analysis metrics.
- ⚒ code2flow: Generate call graphs.
Performance / Profiling
- ⚒ viztracer + vizplugins: VizTracer is a low-overhead logging/debugging/profiling tool that can trace and visualize your python code execution.
- airspeed velocity: tool for benchmarking Python packages over their lifetime.
- perflint: Pylint extension for performance anti patterns.
- ★ ⚒ py-spy: Sampling profiler, can export results to speedscope-format.
- ⚒ memray: Tracing memory profiler with nice reports and a live-view in terminal.
- ⚒ fastero:
timeit
, but nicer. - ⚒ pyinstrument: Statistical profiling (samples from callstack with little overhead).
- ⚒ eliot: For causal logging (tracing).
- airspeed velocity: Benchmark project through development lifetime.
Package assessment
- ⚒ libhunt.com: Maintenance and usage stats for Python libraries. Compare various packages against each other.
- ⚒ libraries.io: Assess maintenance and usage stats of Python libraries.
- ⚒ snyk.io: Search and compare over 1 million open source packages.
Security
- ★ Bandit: A security linter from PyCQA.
- ★ pip-audit: Tool by PyPa for scanning Python environments for packages with known vulnerabilities.
- pyscan: Tool for scanning Python environments for packages with known vulnerabilities. Uses OSV database.
Testing
- pytest-parallel: Multiprocessing (or threading) to run tests faster.
- ⚒ mutmut & cosmic ray: Mutation testing to identify white spots in your tests.
- slipcover: Newer test coverage tool with less overhead than
coverage.py
- ★locust and locust-grasshopper: Load testing of e.g. REST APIs.