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.4

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.4
File Actions
php_parser_py-1.2.4-py3-none-win_amd64.whl Python 3 none Windows x86-64 Details for php_parser_py-1.2.4-py3-none-win_amd64.whl
php_parser_py-1.2.4-py3-none-manylinux_2_17_x86_64.whl Python 3 none Linux glibc 2.17+ x86-64 Details for php_parser_py-1.2.4-py3-none-manylinux_2_17_x86_64.whl
php_parser_py-1.2.4-py3-none-manylinux_2_17_aarch64.whl Python 3 none Linux glibc 2.17+ ARM64 Details for php_parser_py-1.2.4-py3-none-manylinux_2_17_aarch64.whl
php_parser_py-1.2.4-py3-none-macosx_11_0_x86_64.whl Python 3 none macOS 11.0+ x86-64 Details for php_parser_py-1.2.4-py3-none-macosx_11_0_x86_64.whl
php_parser_py-1.2.4-py3-none-macosx_11_0_arm64.whl Python 3 none macOS 11.0+ ARM64 Details for php_parser_py-1.2.4-py3-none-macosx_11_0_arm64.whl

Total release size: 20.4 MB

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

Download URL php_parser_py-1.2.4-py3-none-win_amd64.whl
Size 6.9 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
496be1843fc19d68f3894905ce261fd94907f9d05e06e5fe9ee23e2afa322b0f
BLAKE2b-256 checksum
How to use checksums
9c07ba53688c2b4867a7b44dd70366be9651ff0bbf7236d052c5475314eb7c67
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.4-py3-none-manylinux_2_17_x86_64.whl

Download URL php_parser_py-1.2.4-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
1f7946cd81c3c1e01b516ab9369525b185130e8be516843fe20b382d15c4bbe7
BLAKE2b-256 checksum
How to use checksums
20ac5e51d8d1245696f63031b4c2aad158c35852103b8fad8197913b31fedae5
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.4-py3-none-manylinux_2_17_aarch64.whl

Download URL php_parser_py-1.2.4-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
c8b507202e6289e7a9c8c77f2d0b2633ca8466bf51027dd09fb7be8b992116b5
BLAKE2b-256 checksum
How to use checksums
0765e197bb94565998dbac0ae7724d706e94d71369b425ab6d92ba105c7ca1dc
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.4-py3-none-macosx_11_0_x86_64.whl

Download URL php_parser_py-1.2.4-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
5c5211fe9ccea8acb0c0c427693f59d4e836d8de1c9d8b83c7fe10f686960b1b
BLAKE2b-256 checksum
How to use checksums
11487e16b4c5bd820cd6992987aef50a3c5ce6a5c6f3f5821bbbc978edcf4ef3
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.4-py3-none-macosx_11_0_arm64.whl

Download URL php_parser_py-1.2.4-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
c6492c057c627885c51d4d9d20eb53f172d78eba67f1f89a28107d91679cf71c
BLAKE2b-256 checksum
How to use checksums
724d4ab964d44bb7452fe20eb6e127f7358b8bace829597868190e16bbbece99
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.4

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