Registry / testing / yapf
library0.43.0pypypi✓ verified 24d ago

YAPF (Yet Another Python Formatter) is an opinionated code formatter for Python, developed by Google. It automatically re-formats Python code to conform to the PEP 8 style guide and other configurable style conventions, aiming to improve code readability and consistency. The current version is 0.43.0, and it generally follows a stable release cadence with updates for Python version support and bug fixes.

pip install yapf
INSTALL
IMPORT
SIG · YAPF
Y
yapf
testingpythonv0.43.0
Install
1.8s avg
Import
Disk
18MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.43.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 20.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.8s · import 0.000s · 21MB
18MB installed
● package 18MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

FormatCode
from yapf.yapf_api import FormatCode
from yapf.yapf_api import FormatCode
FormatFiles
from yapf import FormatFiles
from yapf.yapf_api import FormatFiles
main
from yapf import main
from yapf.yapf_api import main

Demonstrates how to use `FormatCode` to programmatically format a string of Python code, including an example of applying a specific style configuration.

from yapf.yapf_api import FormatCode unformatted_code = """ def example_function( arg1, arg2 = None ): if arg1 : print( "Hello", arg1 ) else: return arg2 """ formatted_code, changed = FormatCode(unformatted_code) print("--- Original ---") print(unformatted_code) print("\n--- Formatted ---") print(formatted_code) print(f"\nChanged: {changed}") # You can also pass style parameters formatted_code_google, _ = FormatCode(unformatted_code, style_config='google') print("\n--- Formatted (Google Style) ---") print(formatted_code_google)
yapf --version
Debug
Known issues
breakingPython 3.6 support was dropped in YAPF version 0.37.0. Subsequent versions (including 0.43.0) require Python 3.7 or newer.
fix
Ensure your environment uses Python 3.7 or a later version. Upgrade your Python interpreter if necessary.
affects: >=0.37.0
gotchaFor CLI usage, files are not modified in-place by default. If you run `yapf file.py`, it will print the formatted code to stdout but leave the original file untouched.
fix
To modify files in-place, always use the `-i` or `--in-place` flag (e.g., `yapf -i file.py`).
affects: All versions
gotchaConfiguration for programmatic use (e.g., `FormatCode`) does not automatically discover `.style.yapf` or `pyproject.toml` files from the current working directory. You must explicitly pass `style_config` or other parameters.
fix
Pass `style_config='google'` (or other predefined styles), or a dictionary of style options directly to `FormatCode`. For file-based configuration, load it manually and pass the dictionary, or invoke YAPF via its CLI which handles file discovery.
affects: All versions
gotchaInternal AST representation changed from `pytree` to `libcst` in version 0.40.0. While this is primarily an internal refactoring, users who relied on direct interaction with YAPF's internal AST objects might experience compatibility issues.
fix
Avoid relying on YAPF's internal AST structures. If you need to manipulate ASTs, use `libcst` directly or ensure your integration is compatible with the new underlying library.
affects: >=0.40.0
Upgrade
Version history
0.43.0latest on PyPI · released Nov 14, 2024
Audit
Dependencies

No dependency data recorded yet.

Agent activity
38 hits · last 30 days
node
34
OpenAI (training)
1
Resources
yapf — pip install yapf · libregistry