A curated list of awesome Python code formatters
- 2to3 -- Automated Python 2 to 3 code translation.
- add-trailing-comma -- A tool to automatically add trailing commas to calls and literals.
- autopep8 -- A tool that automatically formats Python code to conform to the PEP 8 style guide.
- black -- The uncompromising Python code formatter.
- com2ann -- Translates type comments to type annotations.
- decrapify -- Some scripts that use pybowler.io for refactoring Python code.
- docformatter -- Formats docstrings to follow PEP 257.
- eradicate -- Removes commented-out code from Python files.
- formate -- A wrapper around isort and yapf with a few custom rules.
- pep585-upgrade -- Automatically upgrade your type hints to the new native types implemented in PEP 585.
- prettier -- An opinionated code formatter, not only for Python.
- pybetter -- Tool for fixing trivial problems with your code.
- pyment -- A tool to format and generate docstrings.
- pyupgrade -- A tool to automatically upgrade syntax for newer versions of the language.
- reindent.py -- Change Python (.py) files to use 4-space indents and no hard tab characters.
- teyit -- Unittest assertion formatter.
- unify -- Modifies strings to all use the same quote where possible.
- yapf -- Yet another Python code formatter from Google.
- flynt -- A tool to automatically convert old string literal formatting to f-strings.
- ssort -- Sorts the contents of python modules so that statements are placed after the things they depend on, but leaves grouping to the programmer. Groups class members by type and enforces topological sorting of methods.
- absolufy-imports -- Convert relative imports to absolute.
- autoflake -- Removes unused imports and unused variables as reported by pyflakes.
- isort -- A Python utility / library to sort imports.
- pycln -- Removes unused imports.
- reorder-python-imports -- Reorders imports.
- removestar -- Tool to automatically replace
import *
in Python files with explicit imports. - unimport -- Removes unused imports.
- pyall -- Pyall is a linter that tries to keep the
__all__
in your Python modules always up to date.
- black-macchiato -- paints part of your python code black.
- blacken-docs -- Run
black
on python code blocks in documentation files. - brunette -- best practice Python code formatter, wrapper around
black
with improvements. - formate-black -- a black integration for formate.
- gray -- wrapper around
isort
,pyupgrade
,add-trailing-comma
, andunify
. - jupyterlab_code_formatter -- A universal code formatter for JupyterLab.
- pyformat -- wrapper around
autopep8
,autoflake
,docformatter
, andunify
. - shed -- wrapper around
autoflake
,black
,com2ann
,isort
,pybetter
,pyupgrade
, andteyit
; with fully automatic configuration andblacken-docs
-inspired support for code in docs files too.
- bowler -- Safe code refactoring for modern Python.
- fissix -- backport of lib2to3, with enhancements.
- massedit -- edit text files with Python.
- rope -- a python refactoring library.
- undebt -- tool for performing massive, automated Python code refactoring.
- LibCST -- LibCST parses Python 3 source code as a CST tree that keeps all formatting details (comments, whitespaces, parentheses, etc). It's useful for building automated refactoring applications and linters.
- django-codemod -- A tool to help upgrade Django projects to newer version of the framework by automatically fixing deprecations.
- Refactor -- AST-based fragmental source code refactoring toolkit
This list doesn't contain tools that generate code, type annotations, comments etc. The difference is that code formatters transform your code from one form into another (which should be safe if the tool is stable) while code generators bring something totally new. If you're looking for code generators, check out the following links:
- awesome-python-typing -- tools to generate type annotations.
- awesome-python-testing -- tools to generate tests.