explaingit

google/yapf

13,980PythonAudience · developerComplexity · 1/5LicenseSetup · easy

TLDR

YAPF is a command-line tool that automatically reformats Python code to match a chosen style guide, PEP 8 or Google style, so you never spend time manually fixing spacing or indentation again.

Mindmap

mindmap
  root((YAPF))
    What It Does
      Auto-format code
      Style enforcement
      Diff output
    Built-in Styles
      PEP 8
      Google style
      Custom config
    How to Run
      Command line
      In-place rewrite
      CI check mode
    Editor Support
      VS Code plugin
      Auto on save
      Parallel files
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Automatically reformat all Python files in a project to match PEP 8 style with a single command.

USE CASE 2

Add YAPF as a pre-commit check in your CI pipeline to reject code that does not meet your style rules.

USE CASE 3

Integrate YAPF with your code editor to auto-format Python files every time you save.

Tech stack

Python

Getting it running

Difficulty · easy Time to first run · 5min
Use freely for any purpose, including commercial use, as long as you keep the copyright notice. (Apache-style license from Google)

In plain English

YAPF is a tool that automatically formats Python code so it looks clean and consistent. If you have ever spent time manually adjusting spacing, indentation, or line lengths in a Python file to match a style guide, YAPF does that work for you. You point it at a file, it rewrites the formatting, and you move on. The tool works by calculating the best possible layout for your code according to a chosen style. You can pick from a few built-in styles, including the official Python community style (PEP 8) and Google's internal Python style. You can also create a configuration file to mix and match specific rules, such as how many spaces to use before a comment or whether to break lines before certain operators. YAPF runs from the command line. You can ask it to rewrite files in place, print only the changes it would make, or check whether a file is already formatted correctly (useful for automated checks during software development). It can process a single file, a folder of files, or read code piped in from elsewhere. An option to run on multiple files at once using parallel processing is also available. Many popular code editors have plugins that run YAPF automatically when you save a file, so you may never need to invoke it manually. It installs from the standard Python package index with a single command. The project was originally created at Google but is not an official Google product. The full README is longer than what was shown.

Copy-paste prompts

Prompt 1
How do I run YAPF on an entire Python project folder to reformat all .py files in place using Google style?
Prompt 2
Set up a .style.yapf config file that uses PEP 8 but allows lines up to 100 characters and puts closing brackets on their own line.
Prompt 3
Add YAPF to a GitHub Actions workflow so pull requests are automatically rejected if any Python file is not properly formatted.
Prompt 4
My editor is VS Code. How do I configure it to run YAPF automatically every time I save a Python file?
Prompt 5
How do I use YAPF's --diff flag to preview what it would change without actually rewriting my files?
Open on GitHub → Explain another repo

← google on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.