Skip to main content

Python wrapper for PHP-Parser using cpg2py

Project description

php-parser-py

Ask DeepWiki

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

Requirements

  • Python ≥ 3.11
  • (Optional) Custom PHP binary can be configured via Parser constructor.

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

php_parser_py-1.2.2.tar.gz (309.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

php_parser_py-1.2.2-py3-none-any.whl (313.4 kB view details)

Uploaded Python 3

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

Hashes for php_parser_py-1.2.2.tar.gz
Algorithm Hash digest
SHA256 3e45977a4554f10df7deb0039b2bdf2a6c0c6f11089e933be8a9cab22422a029
MD5 f45ec447a1858987bcd41dea129c56a8
BLAKE2b-256 2860031eda0394ec5264f7f2db539f20b5ec6276d143722a11ca2bac5845546e

See more details on using hashes here.

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

Hashes for php_parser_py-1.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 821a67e6671e912cf95cc676bf7b8969e97a6fea5cfb0a12ac7fb8207af4be63
MD5 b521d6296b783c5b7377c89a87e993ef
BLAKE2b-256 4788c7b608af89b8bb5bc8b9f49e40bbcb1140ed0054a4051cd2eba4bfb34296

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page