Skip to main content

php-parser-py

php + parser + py: nikic/PHP-Parser, driven from Python.

Parse, query, mutate, and regenerate PHP code in Python through a graph API — no local PHP required.

Install

# via uv
uv add php-parser-py

# or via pip
pip install php-parser-py

Requires Python >= 3.11.

Usage

from php_parser_py import parse_file, Modifier

# Parse
ast = parse_file("src/User.php")

# Query
functions = ast.nodes(lambda n: n.node_type == "Stmt_Function")
for func in functions:
    params = [c for c in ast.succ(func) if c.node_type == "Param"]

# Modify structure (copy-on-write: source `ast` is untouched)
modifier = Modifier(ast)
modifier.add_node("new_1", "Stmt_Break")
modifier.add_edge("parent_id", "new_1", field="stmts", index=0)
modified = modifier.ast

API

Function / Class Signature Description
parse_code (code: str) -> list[Node] Parse PHP string into statement nodes
parse_file (path: str) -> AST Parse single file with project/file structure
parse_project (project_path: str, file_filter?) -> AST Parse all PHP files in a directory
Modifier (ast: AST) Copy-on-write graph mutation; read result from modifier.ast
AST.nodes (predicate?) -> Generator[Node] Iterate/filter nodes
AST.succ (node) -> Generator[Node] Get children
AST.prev (node) -> Generator[Node] Get parents
AST.first_node (predicate) -> Node | None First matching node
Node.node_type -> str PHP-Parser node type (e.g. "Stmt_Function")
Node.start_line -> int Source line number

Full specifications in docs/design-parser.md and docs/design-graph.md.

Background

Python wrapper for nikic/PHP-Parser built on the cpg2py graph framework. Ships a static PHP binary in platform-specific wheels; falls back to a php on PATH when no bundled binary matches the host.

Documentation

  • Concepts — problem scope, data flow, and core terminology.
  • Design — architecture, class specifications, and mapping rules.
  • AST Reference — complete table of PHP-Parser node types.
  • cpg2py API — graph querying patterns.

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{citation_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.

Metadata

Release files for php-parser-py 1.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for php-parser-py 1.2.5
File Actions
php_parser_py-1.2.5-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for php_parser_py-1.2.5-py3-none-win_amd64.whl
php_parser_py-1.2.5-py3-none-manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for php_parser_py-1.2.5-py3-none-manylinux_2_17_x86_64.whl
php_parser_py-1.2.5-py3-none-manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for php_parser_py-1.2.5-py3-none-manylinux_2_17_aarch64.whl
php_parser_py-1.2.5-py3-none-macosx_11_0_x86_64.whl Python 3 none macOS 11.0+ x86-64 Details for php_parser_py-1.2.5-py3-none-macosx_11_0_x86_64.whl
php_parser_py-1.2.5-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for php_parser_py-1.2.5-py3-none-macosx_11_0_arm64.whl

Total release size: 20.4 MB

Release files / php_parser_py-1.2.5-py3-none-win_amd64.whl

Download URL php_parser_py-1.2.5-py3-none-win_amd64.whl
Size 6.9 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
c962432298c905d1a3aae06d5f2f1d937f73a9616115fd17e00d2b47f6e36e39
BLAKE2b-256 checksum
How to use checksums
9968738d69bba5961cf4bc53c5c3d33ea3ab2e293f539762dabfab9e94af046d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / php_parser_py-1.2.5-py3-none-manylinux_2_17_x86_64.whl

Download URL php_parser_py-1.2.5-py3-none-manylinux_2_17_x86_64.whl
Size 3.3 MB
Tags Linux glibc 2.17+ x86-64 Python 3
SHA-256 checksum
How to use checksums
750516d719d13ccbadc376ac5ea8711bdea484b3e28c45ab588a311b4ef68ef1
BLAKE2b-256 checksum
How to use checksums
e8975733238aebc98a201564b50b8490133f2b1c6dc8355c2682749016df4754
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / php_parser_py-1.2.5-py3-none-manylinux_2_17_aarch64.whl

Download URL php_parser_py-1.2.5-py3-none-manylinux_2_17_aarch64.whl
Size 3.3 MB
Tags Linux glibc 2.17+ ARM64 Python 3
SHA-256 checksum
How to use checksums
2fae2561834cf06ae64caee47e0147e5662dacab6ef3703524ed5e1c51c03175
BLAKE2b-256 checksum
How to use checksums
b4904c11bc21f57e9b0ac40ec107d000c15ce1d5e22ea0365b81d77bd740898b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / php_parser_py-1.2.5-py3-none-macosx_11_0_x86_64.whl

Download URL php_parser_py-1.2.5-py3-none-macosx_11_0_x86_64.whl
Size 3.6 MB
Tags Python 3 macOS 11.0+ x86-64
SHA-256 checksum
How to use checksums
b28fb7cc722845288b42dd7e563e1061a34efff368c1228a673b9367c25dbd67
BLAKE2b-256 checksum
How to use checksums
19a002a9f58d9c3967d031f32bb210ba4143149bb6be4c30b04a4490168858cf
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Release files / php_parser_py-1.2.5-py3-none-macosx_11_0_arm64.whl

Download URL php_parser_py-1.2.5-py3-none-macosx_11_0_arm64.whl
Size 3.4 MB
Tags Python 3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
7e7379f9ef664610a676b35910705e52076c77a3e762140079b1b83976eeff92
BLAKE2b-256 checksum
How to use checksums
2deb049c95c41a3cd1c20d2b984a01b2d9ceed57a1241b865fa4da837ce7a879
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.13

Security for php-parser-py 1.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page