Skip to main content

php-parser-py

PHP's parser, in py - Drive nikic/PHP-Parser 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.10.

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

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

Total release size: 20.4 MB

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

Download URL php_parser_py-1.2.6-py3-none-win_amd64.whl
Size 6.9 MB
Tags Python 3 Windows x86-64
SHA-256 checksum
How to use checksums
3d416387d8e10127f2d16261fca265bd21bfb1af2e983b2449f0f538929d4761
BLAKE2b-256 checksum
How to use checksums
24babe388871c6cb8a8f724c55b00ea439e20a026199a530d6603830d3389b75
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.6-py3-none-manylinux_2_17_x86_64.whl

Download URL php_parser_py-1.2.6-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
31e7ba024e213d981116e5962d1916aeb29bece6308639e93e4cce66a1fdd5d2
BLAKE2b-256 checksum
How to use checksums
b7019acebb23592cf32712d614cd7987210f475ad815898e7c39e9ffa424fe57
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.6-py3-none-manylinux_2_17_aarch64.whl

Download URL php_parser_py-1.2.6-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
1f79f4440bee5b31978f5765b6055fb5a00624a35caaa0837ea004b133a5798e
BLAKE2b-256 checksum
How to use checksums
aa64111f4c44d7349685c330b010c287d8d219924afcec48602747e81270fa42
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.6-py3-none-macosx_11_0_x86_64.whl

Download URL php_parser_py-1.2.6-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
d6b857b9ff895dd4294898a7e72e144425abaaa67f5e37932abe6dda6be3997d
BLAKE2b-256 checksum
How to use checksums
dc4aa42961b4f3bd519ca2222a9c744cf4fa35d4729c3de26314c117bb1aee96
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.6-py3-none-macosx_11_0_arm64.whl

Download URL php_parser_py-1.2.6-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
a7ad745264ba2c80c2a362524c6505097a6105550141bc9144c4e088aef1a49f
BLAKE2b-256 checksum
How to use checksums
84fe182af6fb641375063bd52b7188c9c17d72fd1d5622aeaa326b4a07e82ab6
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.6

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