Python wrapper for PHP-Parser using cpg2py
Project description
php-parser-py
Python wrapper for nikic/PHP-Parser built on the cpg2py graph framework.
- Automated: Uses static-php-cli binaries (no local PHP required).
- Graph-Based: AST nodes are stored in a queryable graph database.
- Accurate: Full support for PHP-Parser 4.19.4 AST structure.
Quick Start
pip install php-parser-py
from php_parser_py import parse_file, parse_project
# 1. Parse
ast = parse_file("src/User.php")
# ast = parse_project("src/")
# 2. Traverse
files = ast.file_nodes()
# Find specific nodes
functions = ast.nodes(lambda n: n.node_type == "Stmt_Function")
# Get properties (scalars)
for func in functions:
print(f"Function: {func['namespacedName']}")
# Get child nodes (structure)
for func in functions:
# Use helper method or traverse edges
params = [c for c in ast.succ(func) if c.node_type == "Param"]
Documentation
-
Architecture & Design Detailed design documentation covering internal architecture, class specifications, and design rationale.
-
AST Structure Reference
Complete table of all node types, subnodes (children), and properties. Verified against PHP-Parser source. -
Graph Traversal Guide
How to navigate the graph (succ,prev), access properties, and modify the graph (set_property).
Requirements
- Python ≥ 3.11
- (Optional) Custom PHP binary can be configured via
Parserconstructor.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
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_parser_py-1.2.1.tar.gz.
File metadata
- Download URL: php_parser_py-1.2.1.tar.gz
- Upload date:
- Size: 309.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0370c46317e41779b58eaf8f5af3b0756a0ba70390d254ee45265517a0379e3b
|
|
| MD5 |
9a09bb164b2d46e3eab242a74c7f4144
|
|
| BLAKE2b-256 |
1758c9f9f85521184cb77c2453d48ca514e62d6688c8b0d33c62bcf84857b328
|
File details
Details for the file php_parser_py-1.2.1-py3-none-any.whl.
File metadata
- Download URL: php_parser_py-1.2.1-py3-none-any.whl
- Upload date:
- Size: 312.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9b1dbca7d1f857068d6f2bcdf6a17cafbaa850b3e77f73b9b3bc9d808aabefa
|
|
| MD5 |
a06993161a21f6c4cc5fe06e1f300091
|
|
| BLAKE2b-256 |
c6366cdc22eab18fece6e383706711fb592349520c2b936f5ae90f3be9bc57ea
|