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-py 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, Modifier
# 1. Parse
ast = parse_file("src/User.php")
# 2. Query
functions = ast.nodes(lambda n: n.node_type == "Stmt_Function")
for func in functions:
print(f"Function: {func['namespacedName']}")
params = [c for c in ast.succ(func) if c.node_type == "Param"]
# 3. Modify properties
func.set_property("analyzed", True)
# 4. Modify structure
modifier = Modifier(ast)
modifier.add_node("new_1", "Stmt_Break")
modifier.add_edge("parent_id", "new_1", field="stmts", index=0)
modifier.remove_node("obsolete_node_id")
Documentation
-
Architecture & Design Internal architecture, class specifications, and design rationale.
-
AST Structure Reference
Complete table of all node types, subnodes (children), and properties. -
cpg2py Graph API
Querying (nodes,succ,prev)
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.2.tar.gz.
File metadata
- Download URL: php_parser_py-1.2.2.tar.gz
- Upload date:
- Size: 309.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e45977a4554f10df7deb0039b2bdf2a6c0c6f11089e933be8a9cab22422a029
|
|
| MD5 |
f45ec447a1858987bcd41dea129c56a8
|
|
| BLAKE2b-256 |
2860031eda0394ec5264f7f2db539f20b5ec6276d143722a11ca2bac5845546e
|
File details
Details for the file php_parser_py-1.2.2-py3-none-any.whl.
File metadata
- Download URL: php_parser_py-1.2.2-py3-none-any.whl
- Upload date:
- Size: 313.4 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 |
821a67e6671e912cf95cc676bf7b8969e97a6fea5cfb0a12ac7fb8207af4be63
|
|
| MD5 |
b521d6296b783c5b7377c89a87e993ef
|
|
| BLAKE2b-256 |
4788c7b608af89b8bb5bc8b9f49e40bbcb1140ed0054a4051cd2eba4bfb34296
|