Metadata-Version: 2.4
Name: php-parser-py
Version: 2.1.0
Summary: Python wrapper for PHP-Parser using cpg2py
License-Expression: GPL-2.0-only
License-File: LICENSE
License-File: PHP-LICENSE
License-File: PHP-Parser-LICENSE
License-File: Zend-Engine-LICENSE
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Programming Language :: Python :: 3
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Requires-Python: >=3.10
Requires-Dist: cpg2py>=1.2.0
Requires-Dist: static-php-py==0.2.0
Description-Content-Type: text/markdown

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

## Install

```bash
# via uv
uv add php-parser-py

# or via pip
pip install php-parser-py
```

Requires Python >= 3.10.

## Usage

```python
from pathlib import Path
from tempfile import TemporaryDirectory

from php_parser_py import PHPVersion, StandardPrinter, parse_file

with TemporaryDirectory() as directory:
    path = Path(directory) / "example.php"
    path.write_text("<?php echo 1;", encoding="utf-8")
    ast = parse_file(str(path), target_php=PHPVersion(8, 3))
    echoes = list(ast.nodes(lambda node: node.node_type == "Stmt_Echo"))
    print(next(iter(StandardPrinter().print(ast).values())))
```

## API

- [Parsing and target types](docs/design-parser.md)
- [Graph and node interfaces](docs/design-graph.md)
- [Structural mutation](docs/design-mutation.md)
- [Printing interfaces](docs/design-printer.md)

## Documentation

- **[Concepts](docs/concept.md)** — problem scope, data flow, and core terminology.
- **[Design](docs/index.md)** — architecture, class specifications, and mapping rules.
- **[AST Reference](docs/libs/php_parser_ast.md)** — complete table of PHP-Parser node types.
- **[cpg2py API](docs/libs/cpg2py.md)** — graph querying patterns.

## For Agents

Agent-consumable documentation index at [docs/llms.txt](docs/llms.txt) (llmstxt.org format).

## License

GPL-2.0-only — see [LICENSE](LICENSE).
