A build-plugin framework for Gradle and Maven that runs code formatters and linters across many languages and file types.
google/yapf
A Python code formatter that reformats source files to a configurable style, based on clang-format's layout algorithm.
Open-source alternative to:Black
- Stars
- 13,986
- Forks
- 914
- Open issues
- 433
- Last commit
- yesterday
What is it?
YAPF formats Python source code by computing the best layout that conforms to a chosen style, so developers spend less time manually fixing indentation, spacing and line breaks. It is built on the reformatting algorithm from clang-format and can be run from the command line or called as a library through the FormatCode and FormatFile functions.
Style is controlled through predefined bases such as pep8, google, yapf and facebook, which can be customized with key/value settings in a .style.yapf, setup.cfg, pyproject.toml file or on the command line. Many individual options cover things like column limit, bracket placement, operator splitting and comment spacing.
YAPF can reformat only selected line ranges, exclude files via command-line patterns or a .yapfignore file, print diffs, and run in parallel across multiple files. Its --diff mode returns a non-zero exit code when changes are needed, which makes it usable as a check in CI.
Key features
- 01Reformats Python files to a predefined or custom style such as pep8 or google.
- 02Customizable through dozens of style options in config files or on the command line.
- 03Can format only specified line ranges of a file.
- 04Supports exclusion patterns via command line or .yapfignore / pyproject.toml.
- 05Provides a diff mode that exits non-zero when formatting changes are needed, suitable for CI checks.
- 06Usable as a command-line tool or a Python library.
Use cases
- Enforcing a consistent code style across a Python team or repository.
- Adding a formatting check to a CI pipeline using diff mode.
- Formatting only the lines touched by a patch or edit in an editor integration.
- Automating style cleanup in scripts that generate or transform Python code.
Quick start
- 1
Install YAPF from PyPI
pip install yapf - 2
Run yapf on your Python files, using options such as --diff or --in-place
Things to know
- The README describes YAPF as beta, and releases may change often.
- Some newer Python features, such as PEP 695 type parameter syntax and PEP 701 f-string formalization, are not yet supported.
In collections
Topics
FAQ
- What is yapf?
- A Python code formatter that reformats source files to a configurable style, based on clang-format's layout algorithm. YAPF formats Python source code by computing the best layout that conforms to a chosen style, so developers spend less time manually fixing indentation, spacing and line breaks. It is built on the reformatting algorithm from clang-format and can be run from the command line or called as a library through the FormatCode and FormatFile functions.
- Is yapf free to use? What license does it have?
- yapf is open source under the Apache-2.0 license. Check the license terms before using it in commercial products.
- Is yapf still maintained?
- Actively maintained. The last commit to yapf was on Nov 6, 2026.
- What can I use yapf for?
- Enforcing a consistent code style across a Python team or repository. Adding a formatting check to a CI pipeline using diff mode. Formatting only the lines touched by a patch or edit in an editor integration. Automating style cleanup in scripts that generate or transform Python code.
- How do I install yapf?
- Install YAPF from PyPI: pip install yapf Run yapf on your Python files, using options such as --diff or --in-place
- Where can I get yapf?
- The source code and installation instructions are on GitHub: https://github.com/google/yapf
Summary generated by AI from the project's README. GitHub stats refresh daily.
Related projects
Black is an opinionated, deterministic Python code formatter that rewrites files in place with minimal diffs.
A Ruby static code analyzer and formatter that enforces community Ruby Style Guide rules and can auto-fix many violations.
A Python utility and library that automatically sorts and groups your import statements.
A PHP command-line tool that automatically fixes code to follow PHP coding standards such as PER-CS and Symfony.
An extremely fast Python linter and code formatter written in Rust, with over 900 lint rules and Black-compatible formatting.