Configurable Python code formatter based on clang-format's algorithm
open sourceApache-2.0free
YAPF is an Apache-2.0 Python formatter from a repository Google owns, built on the algorithm of clang-format: it calculates the best layout for the code that conforms to the configured style (pep8, google, facebook or your own settings in a style file) rather than only fixing style violations. It runs as a CLI or a library, supports Python 3.7+, and has community plugins for many editors. Its README calls it beta and says it isn't an official Google product. Development has stalled: the last commit to its main branch was in February 2025. Black is the widely used alternative.
Problems it solves
- reformat my Python code with a style I can configure
- a Python formatter that follows the Google style guide
- keep Python formatting consistent across my team without arguing about style
Features
- reformats code to the best layout for a chosen style, not only style fixes
- built-in pep8, google and facebook styles, or your own style file
- CLI and Python library, with community editor plugins
Limitations
Alternatives
The same job
These do what YAPF does.
- Black The uncompromising Python code formatter: one deterministic style, no configuration debates
- Ruff An extremely fast Python linter and code formatter, written in Rust
- autopep8 Automatically reformats Python code to follow the PEP 8 style guide
- Airbnb Swift Style Guide Airbnb's Swift style guide, with a SwiftPM plugin that formats and lints to it
