YAPF – Python formatter based on clang-format

YAPF (Yet Another Python Formatter) is a Python source code formatter based on the formatting approach used by clang-format. It analyses source code and determines a layout that conforms to a specified set of style rules.

The program offers extensive configuration, allowing developers to customise the appearance of their code. This makes it particularly useful for projects with established formatting conventions that cannot easily be reproduced by more opinionated tools.

YAPF attempts to produce code that resembles what a developer would write when following a style guide consistently. It supports both command-line operation and programmatic use, making it suitable for individual developers and larger projects requiring automated formatting.

This is free and open source software.

Key Features

  • Automatically reformats Python code according to configurable style rules.
  • Uses a formatting algorithm inspired by clang-format.
  • Includes predefined PEP 8, Google, YAPF and Facebook formatting styles.
  • Supports custom formatting styles based on existing profiles.
  • Provides extensive controls for indentation, spacing, line length and expression wrapping.
  • Offers configurable formatting of brackets, operators, comprehensions and function calls.
  • Reads formatting settings from .style.yapf, setup.cfg and pyproject.toml files.
  • Can format entire files or selected line ranges.
  • Supports recursive processing of directory trees.
  • Offers parallel processing when formatting multiple files.
  • Provides diff mode for reviewing proposed changes without modifying source code.
  • Supports patterns for excluding selected files from formatting.
  • Allows sections of source code to be excluded using formatting directives.
  • Provides FormatCode and FormatFile APIs for integration with Python applications.
  • Includes yapf-diff for formatting lines associated with source code changes.
  • Supports editor integration through community-developed plugins and extensions.

Website: github.com/google/yapf
Support:
Developer: Google
License: Apache License 2.0

YAPF is written in Python. Learn Python with our recommended free books and free tutorials.


Related Software

Python Code Formatters
RuffExtremely fast Python linter and code formatter
YAPFPython formatter based on clang-format
BlackUncompromising Python code formatter
isortPython utility and library to sort imports
autopep8Formats Python code to conform to the PEP 8 style guide
DarkerApply black reformatting to Python files
PyinkPython code formatter
docformatterAutomatically formats Python docstrings for consistent style
SSortSorts Python statements by dependency for clearer code
reorder-python-importsReorders Python imports into a consistent, readable layout
μsortSorts import statements
eradicateRemove commented-out code from Python files

Read our verdict in the software roundup.


Best Free and Open Source Software LinuxLinks helps you discover the best free and open source software for Linux. Explore our extensive collection of recommended applications, including alternatives to popular proprietary software.

We also publish software reviews, Linux tutorials, hardware reviews, free programming books and articles covering the wider open source community. Browse our Linux resources to discover more.

Know a useful free and open source Linux application we haven't covered? Suggest a program for inclusion.

Has your software been featured on LinuxLinks? Display one of our Featured on LinuxLinks badges on your website or GitHub README.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted