yapf
A formatter for Python code
What it is and what it does
YAPF is a Python code formatter that automatically rewrites code to match a configured style, based on the clang-format algorithm. Rather than enforcing rules line-by-line, it analyzes the entire code structure and calculates the best formatting that conforms to your chosen style. It supports predefined styles (pep8, google, yapf, facebook) and custom configurations via .style.yapf, setup.cfg, or pyproject.toml files.
You can use YAPF as a command-line tool to format files in place, print diffs, or run recursively over directories, or as a Python library by importing FormatCode and FormatFile from yapf.yapflib.yapf_api. It requires Python 3.7 or later and integrates with many editors via community plugins.
Use it for:
- Enforce consistent code style across a team or project without manual review of formatting details.
- Integrate into a CI/CD pipeline to verify that code has been formatted correctly before merging.
- Reformat legacy Python code to a modern style guide in bulk.
- Use as a library in an IDE or editor plugin to format code on save or on demand.
- Configure custom formatting rules for a project and apply them consistently to all Python files.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
YAPF automatically reformats Python code to conform to a specified style guide, calculating the best formatting that matches your chosen style.
Yes. YAPF is actively maintained with low install friction, permissive licensing, and no known vulnerabilities. Install it if you want automatic, style-guide-compliant code formatting in your workflow—either as a standalone tool or integrated into your development environment.
Install
yapf on PyPI
pip
pip install yapfuv
uv add yapfpoetry
poetry add yapfInstalling yapf
Before you install
Low install friction with only two runtime dependencies (platformdirs and tomli). Actively maintained with recent commits and a large repository following (13980 stars).
License in practice
Apache License 2.0 is permissive and allows commercial use, modification, and distribution with minimal restrictions—you can use YAPF in proprietary projects as long as you include a copy of the license and note any changes you make.
Quickstart
pip install yapf
from yapf.yapflib.yapf_api import FormatCode
formatted_code, changed = FormatCode("f ( a = 1, b = 2 )")
print(formatted_code)
Requires Python 3.7 or later (supports 3.7, 3.8, 3.9, 3.10, 3.11)
Verify before relying
- Whether YAPF's formatting output is deterministic across different Python versions or systems.
- Performance characteristics when formatting very large files or entire codebases.
- How well YAPF integrates with modern Python tooling in the same workflow.
Package facts
| License | Apache License Version 2.0, January 2004 http://www.apache.org/licenses/ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 1. Definitions. "License" shall mean the terms and conditions for… (full text in the JSON record) (permissive) |
| Python support | supports the current Python release (>=3.7) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — platformdirs, tomli |
| Maintenance | actively maintained — 638 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 9,155,087/month — #1,557 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: yapf-0.43.0-py3-none-any.whl
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
autopep8autopep8 automatically reformats Python code to…
permissive · top 5,000 on PyPI
reformat-gherkinAutomatically formats Gherkin feature files to…
permissive · top 15,000 on PyPI
yamlfixyamlfix is a command-line YAML formatter that…
copyleft · top 5,000 on PyPI
darkerDarker reformats Python source code in Git…
permissive · top 15,000 on PyPI
ydiffYdiff displays colored, incremental diffs in a…
permissive · top 15,000 on PyPI
bashatebashate is a style checker for bash scripts…
permissive · top 15,000 on PyPI
beautyshBeautysh automatically formats and beautifies…
permissive · top 15,000 on PyPI
pycodestylepycodestyle checks Python code against PEP 8…
permissive · top 1,000 on PyPI
blacken-docsApplies Black code formatting to Python code…
permissive · top 15,000 on PyPI
djadeDjade is a command-line formatter for Django…
permissive · top 15,000 on PyPI