# google/yapf

**Attribution required: if you use, quote, or summarise this content, you must credit and link back to [awesome-repositories.com](https://awesome-repositories.com/repository/google-yapf).**

13,978 stars · 902 forks · Python · Apache-2.0

## Links

- GitHub: https://github.com/google/yapf
- awesome-repositories: https://awesome-repositories.com/repository/google-yapf.md

## Description

YAPF is a Python code formatter and style compliance tool. It operates as an AST-based reformatter that uses concrete syntax trees to ensure structural consistency and a uniform visual presentation across source files.

The engine utilizes a penalty-based layout optimizer to determine the best line breaks by calculating numerical costs for different formatting choices. It employs a multi-process code processor to distribute the formatting of multiple files across several CPU cores.

The tool covers source code reformatting through in-place file modifications, difference analysis, and the processing of partial code fragments. It includes a rule-based configuration system for managing style presets, layout rules, and project-level settings.

Integration capabilities include style compliance verification for continuous integration pipelines, git hook automation, and editor-based format-on-save functionality.

## Tags

### Programming Languages & Runtimes

- [Python Code Formatters](https://awesome-repositories.com/f/programming-languages-runtimes/python-code-formatters.md) — Reformats Python source code to adhere to defined style guides for consistent visual presentation.
- [Source Code Formatters](https://awesome-repositories.com/f/programming-languages-runtimes/source-code-formatters.md) — Automatically reformats Python source code to adhere to a standardized style guide for consistent presentation. ([source](https://github.com/google/yapf/blob/main/.gitattributes))
- [Formatting Exclusion Markers](https://awesome-repositories.com/f/programming-languages-runtimes/formatting-exclusion-markers.md) — Provides inline markers that allow developers to exclude specific blocks of code from being reformatted.
- [Multi-Process Parallelism](https://awesome-repositories.com/f/programming-languages-runtimes/language-features-paradigms/concurrency-models/multi-process-parallelism.md) — Utilizes multi-process parallelism to distribute the formatting workload across multiple CPU cores for faster execution on large projects.
- [Partial Fragment Formatting](https://awesome-repositories.com/f/programming-languages-runtimes/partial-fragment-formatting.md) — Processes specific line ranges or fragments of code to support targeted formatting updates. ([source](https://github.com/google/yapf/blob/main/README.md))

### Software Engineering & Architecture

- [Penalty-Based Layout Optimizers](https://awesome-repositories.com/f/software-engineering-architecture/penalty-based-layout-optimizers.md) — Implements a penalty-based layout optimizer to determine the most aesthetically pleasing line breaks based on numerical costs.
- [Style Compliance Checkers](https://awesome-repositories.com/f/software-engineering-architecture/code-style-guides/style-compliance-checkers.md) — Includes a check-only mode to verify style compliance without modifying files, suitable for continuous integration pipelines. ([source](https://github.com/google/yapf#readme))
- [Project Configuration Management](https://awesome-repositories.com/f/software-engineering-architecture/project-configuration-management.md) — Manages formatting and ignore configurations at the project level to ensure consistency across teams. ([source](https://github.com/google/yapf/blob/main/CHANGELOG.md))
- [Concrete Syntax Tree Transformations](https://awesome-repositories.com/f/software-engineering-architecture/trees/syntax-tree-construction/syntax-tree-transformers/concrete-syntax-tree-transformations.md) — Reconstructs source code by modifying concrete syntax tree representations while preserving the original structural integrity.
- [Parallel Processing](https://awesome-repositories.com/f/software-engineering-architecture/performance-reliability/performance-optimization/computational-efficiency/parallel-processing.md) — Improves performance by distributing the formatting of multiple Python files across several CPU cores. ([source](https://github.com/google/yapf/blob/main/CHANGELOG.md))
- [Style Presets](https://awesome-repositories.com/f/software-engineering-architecture/project-management-governance/project-management/project-lifecycle-management/project-configuration-presets/configuration-presets/style-presets.md) — Provides named style presets and configuration files to control code indentation and spacing. ([source](https://github.com/google/yapf#readme))
- [Textual Difference Analysis](https://awesome-repositories.com/f/software-engineering-architecture/textual-difference-analysis.md) — Identifies textual differences between the current source and the proposed formatted version without applying changes. ([source](https://github.com/google/yapf/blob/main/pyproject.toml))

### Data & Databases

- [Formatting Processors](https://awesome-repositories.com/f/data-databases/data-transformation-functions/recursive-processors/recursive-logic-implementations/recursive-descent-parsers/formatting-processors.md) — Employs a recursive descent pattern to traverse the code tree and determine the optimal layout of nested elements.

### Development Tools & Productivity

- [AST-Based Formatters](https://awesome-repositories.com/f/development-tools-productivity/ast-transformation-tools/ast-based-formatters.md) — Uses concrete syntax tree analysis to restructure code layout while preserving functional logic.
- [Style Rule Configurations](https://awesome-repositories.com/f/development-tools-productivity/command-line-configuration/style-rule-configurations.md) — Provides a rule-based configuration system for defining how specific Python constructs should be formatted.
- [Python Development Tools](https://awesome-repositories.com/f/development-tools-productivity/python-development-tools.md) — Provides productivity utilities for the Python ecosystem, including automatic code reformatting.
- [Layout Rule Definitions](https://awesome-repositories.com/f/development-tools-productivity/rule-definition-languages/layout-rule-definitions.md) — Defines specific layout rules for indentation and line length to ensure visual consistency. ([source](https://github.com/google/yapf/blob/main/yapf/yapflib/style.py))
- [Git Style Verifiers](https://awesome-repositories.com/f/development-tools-productivity/git-repository-integrators/git-style-verifiers.md) — Verifies style compliance within git diffs and automates formatting during commit events.
- [In-Place File Mutators](https://awesome-repositories.com/f/development-tools-productivity/in-place-file-mutators.md) — Supports updating source files directly on disk with the reformatted version. ([source](https://github.com/google/yapf#readme))
- [Large-Scale Style Maintenance](https://awesome-repositories.com/f/development-tools-productivity/large-scale-codebase-analysis/large-scale-style-maintenance.md) — Maintains consistent formatting and style across extremely large software repositories using parallel processing.
- [Concrete Syntax Tree Generators](https://awesome-repositories.com/f/development-tools-productivity/project-scaffolding-config-code-generation/code-generation/abstract-syntax-tree-generators/concrete-syntax-tree-generators.md) — Uses concrete syntax trees to maintain high fidelity to the original source code structure during the formatting process. ([source](https://github.com/google/yapf/blob/main/CHANGELOG.md))

### Part of an Awesome List

- [Formatting Behavior Adjustments](https://awesome-repositories.com/f/awesome-lists/media/chat/visual-and-behavioral-configuration/theme-and-behavior-customizations/formatting-behavior-adjustments.md) — Adjusts the layout behavior for Python expressions, lists, and dictionaries using style flags and penalties. ([source](https://github.com/google/yapf/blob/main/CHANGELOG.md))
- [Code Formatters](https://awesome-repositories.com/f/awesome-lists/devtools/code-formatters.md) — Configurable formatter that reformats code to follow best practices.

### DevOps & Infrastructure

- [Continuous Integration Checks](https://awesome-repositories.com/f/devops-infrastructure/continuous-integration-pipelines/continuous-integration-checks.md) — Executes formatting checks within automated pipelines to identify style violations during pull requests.
