Python wrapper for PHP-CS-Fixer with a bundled static PHP binary
Project description
php-cs-fixer-py
PHP-CS-Fixer in Python — check and fix PHP code style through a typed API.
Python wrapper for PHP-CS-Fixer — no local PHP or Composer required.
Install
# via uv
uv add php-cs-fixer-py
# or via pip
pip install php-cs-fixer-py
Requires Python >= 3.10. Platform wheels bundle PHP-CS-Fixer 3.95.3 (as PHAR) and a static PHP 8.4 binary (built on static-php-py); a php on PATH is the fallback when no bundled binary matches the host. fixer_version() reports the bundled version at runtime.
Usage
from php_cs_fixer_py import fix, check, Source
# Two verbs. fix changes, check diagnoses. Both return a FixResult.
# Fix files in place
result = fix("src/", rules={"@Symfony": True, "array_syntax": {"syntax": "short"}})
print(f"changed {len(result.files)} files")
# Check files (dry-run) — nothing written
report = check("src/", rules={"@PSR12": True})
if not report.compliant: # CI gate
for f in report.files:
print(f.name, f.applied_fixers)
raise SystemExit(1)
# Fix a source string — wrap in Source.code, read the fixed text off .code
clean = fix(Source.code("<?php $a = array(1,2);"), rules={"@PSR12": True}).code
# Check a source string — same FixResult, ask for .compliant
ok = check(Source.code(clean), rules={"@PSR12": True}).compliant
API
Two verbs split on Command/Query Separation: fix (command) and check (query). Both return a unified FixResult, so the return type depends on the verb, never on the input. Input kind is carried by Source; a bare path works directly, raw source needs Source.code(...).
| Function / Class | Signature | Description |
|---|---|---|
fix |
(source, rules, *, risky=False, **opts) -> FixResult |
Apply fixes (in place for paths) |
check |
(source, rules, *, risky=False, **opts) -> FixResult |
Dry-run; report what would change |
Source.code |
(text) -> Source |
Tag raw PHP source (staged to a temp file) |
Source.path |
(*targets) -> Source |
Tag file/directory paths |
list_rule_sets |
() -> list[str] |
Available @-prefixed rule sets |
fixer_version |
() -> str |
Bundled PHP-CS-Fixer version |
Fixer |
(php=None) |
Class form; reuse one PHP/PHAR resolution |
FixerConfig |
(rules, risky=…, …) |
Optional reusable configuration object |
FixResult.code |
-> str |
Fixed source (after fix on a code source) |
FixResult.compliant |
-> bool |
True when nothing would change |
FixResult.files |
-> tuple[FileResult, …] |
Per-file diffs and applied fixers |
FixResult.changed |
-> bool |
Any file changed / would change |
FixResult.status |
-> FixStatus |
Decoded exit-code flags |
Full specifications in docs/design.md.
Documentation
- Concepts — problem scope, data flow, and core terminology.
- Design — class specifications, public API, module structure.
- Implementation — library APIs, CLI invocation, report schema, exit codes.
For Agents
Agent-consumable documentation index at docs/llms.txt (llmstxt.org format).
Citation
If you use this project in academic work, please cite our paper. BibTeX (placeholder until the paper is released):
@misc{beluga_placeholder,
title = {{TODO: paper title — not yet released}},
author = {{TODO: authors}},
year = {{TODO}},
note = {Paper not yet released. Citation entry will be updated on publication.}
}
License
GPL-2.0 — see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file php_cs_fixer_py-0.1.6-py3-none-win_amd64.whl.
File metadata
- Download URL: php_cs_fixer_py-0.1.6-py3-none-win_amd64.whl
- Upload date:
- Size: 10.1 MB
- Tags: Python 3, Windows x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a6d9227b560eaa851bcfb65a1d553e50e9a27b166e57c305fee3a3ed44a2b26d
|
|
| MD5 |
8f49164bd5bc310f3e62a5587215b457
|
|
| BLAKE2b-256 |
ffb4d5bc047141da870c5037313e770eda168a61427f83b908ee9aa56b179b72
|
File details
Details for the file php_cs_fixer_py-0.1.6-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl.
File metadata
- Download URL: php_cs_fixer_py-0.1.6-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl
- Upload date:
- Size: 9.7 MB
- Tags: Python 3, manylinux: glibc 2.17+ x86-64, musllinux: musl 1.1+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0c0239529b9148c9e40993bda639c17cb2398942f538abbbe0cb6a035bc3cd19
|
|
| MD5 |
7ecfa0287969bc1a5fc499ac1a643118
|
|
| BLAKE2b-256 |
55c9f8f18fba0fdf159a65e161276f1a89296e8a21b4cdc6e66a21d02477e320
|
File details
Details for the file php_cs_fixer_py-0.1.6-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl.
File metadata
- Download URL: php_cs_fixer_py-0.1.6-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl
- Upload date:
- Size: 9.8 MB
- Tags: Python 3, manylinux: glibc 2.17+ ARM64, musllinux: musl 1.1+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beda25ee96b62c456bd0a1a39dba7571b0f0e986dd011701ee7484be5f12cfe8
|
|
| MD5 |
0beed4fe9abc0886a4dd566de5e543fd
|
|
| BLAKE2b-256 |
e60933a18aaeb2da0deb7c3986186cdd1b2a2f34d2d0285c61848a78d66c9690
|
File details
Details for the file php_cs_fixer_py-0.1.6-py3-none-macosx_11_0_x86_64.whl.
File metadata
- Download URL: php_cs_fixer_py-0.1.6-py3-none-macosx_11_0_x86_64.whl
- Upload date:
- Size: 10.2 MB
- Tags: Python 3, macOS 11.0+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
696b0a762550e1b6f7cd471b1ab7299f0381b888b9c0821ddaed0940668af4f6
|
|
| MD5 |
6de37eb14528f88193da45223d5dc650
|
|
| BLAKE2b-256 |
dd12cfaf87186cad9b8bdb4e1e2c782079322667fa7bb460fbc902e3fd5b6804
|
File details
Details for the file php_cs_fixer_py-0.1.6-py3-none-macosx_11_0_arm64.whl.
File metadata
- Download URL: php_cs_fixer_py-0.1.6-py3-none-macosx_11_0_arm64.whl
- Upload date:
- Size: 9.8 MB
- Tags: Python 3, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f634f03884b468e33a7d1768a02a5cd1ad2c9d174bf988f91f9fe75b863304e
|
|
| MD5 |
1fb4971192735a96f8716aa0418bc912
|
|
| BLAKE2b-256 |
cd36af66aaf6068e19dea1704e912761b7180ca4000284592fac4284af611cc0
|