Skip to main content

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 (from GitHub)
uv add php-cs-fixer-py

# or via pip
pip install php-cs-fixer-py

Requires Python >= 3.11. 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

php_cs_fixer_py-0.1.3-py3-none-win_amd64.whl (10.1 MB view details)

Uploaded Python 3Windows x86-64

php_cs_fixer_py-0.1.3-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl (9.7 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ x86-64musllinux: musl 1.1+ x86-64

php_cs_fixer_py-0.1.3-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl (9.8 MB view details)

Uploaded Python 3manylinux: glibc 2.17+ ARM64musllinux: musl 1.1+ ARM64

php_cs_fixer_py-0.1.3-py3-none-macosx_11_0_x86_64.whl (10.2 MB view details)

Uploaded Python 3macOS 11.0+ x86-64

php_cs_fixer_py-0.1.3-py3-none-macosx_11_0_arm64.whl (9.8 MB view details)

Uploaded Python 3macOS 11.0+ ARM64

File details

Details for the file php_cs_fixer_py-0.1.3-py3-none-win_amd64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.3-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 325b917f08822b5a3dd2d3759d98ca0c35fc6dbc401c86483066d32bf665ccce
MD5 23db05fb12f4fb089772317d5b6f5843
BLAKE2b-256 155d76150e261e68b589c922916a436dcf24c3a1f07aeea449ce2970bc610908

See more details on using hashes here.

File details

Details for the file php_cs_fixer_py-0.1.3-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.3-py3-none-manylinux_2_17_x86_64.musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 753a1032646eaab561fe26bc352530ae7d3017351501b8b5f0c1e6af0fb5ad72
MD5 cdc271dcef550c7512bd10f2028dbcdb
BLAKE2b-256 42f66edf56e1f4b9126fcffd0c034a4426db91631cbc5a5306e2a6d8e4d898a4

See more details on using hashes here.

File details

Details for the file php_cs_fixer_py-0.1.3-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.3-py3-none-manylinux_2_17_aarch64.musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 5d01bf77db0a103c769671ee6f44acd8293e3877df4c026a71776b5eade03879
MD5 692ddaa4677b66892cde3166e294a4af
BLAKE2b-256 64c90e00f606c951ca22341ccccbc9ebe47f07a49e934b0bc13abba77e2947fd

See more details on using hashes here.

File details

Details for the file php_cs_fixer_py-0.1.3-py3-none-macosx_11_0_x86_64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.3-py3-none-macosx_11_0_x86_64.whl
Algorithm Hash digest
SHA256 54d8d76aee5ac2c39ac19b0002368c8edfa0608ec84288b9ff29af5afa28d873
MD5 6a5b8d0342da88abd329a96cc934d564
BLAKE2b-256 9f8394a2fba91296eecf4e2c77490af88f5f70849eff5e714a2aebdd1563d1d3

See more details on using hashes here.

File details

Details for the file php_cs_fixer_py-0.1.3-py3-none-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for php_cs_fixer_py-0.1.3-py3-none-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 7c1a5db836569c4f4e593f9544d6ffa8bb519c5873b2b995395ce4dfe0cd3db1
MD5 5ae776edf8f882f192172a2ce5ce19cf
BLAKE2b-256 6410f64be92b02d0faaf821380d78ed4c64666bd7d26f617d56adf2f1dbc54a0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page