Registry / serialization / phply
library1.2.6pypypi✓ verified 93d ago

A lexer and parser for PHP source code implemented using PLY (Python Lex-Yacc). Provides a tokenizer, parser, and AST representation for PHP. Current version 1.2.6, release cadence is sporadic.

pip install phply
INSTALL
IMPORT
SIG · PHPLY
P
phply
serializationpythonv1.2.6
Install
1.7s avg
Import
—
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.2.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.1MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

phply.phpast
✓ from phply import phpast
The AST module is phpast, not phply.ast or phply.phpast as a top-level import.
phply.lexer
✓ from phply import phplex
✗ from phply import lexer
The lexer module is named phplex, not lexer.
phply.parser
✓ from phply import phpparse
✗ from phply import parser
The parser module is named phpparse, not parser.

Basic usage: tokenize and parse a PHP snippet.

from phply import phplex, phpparse from phply import phpast as ast code = '<?php echo "Hello, World!"; ?>' tokens = list(phplex.lex(code)) print('Tokens:', tokens) parser = phpparse.make_parser() parsetree = parser.parse(code, lexer=phplex.lexer) print('AST:', parsetree)
Debug
Known issues
gotchaThe lexer module is called 'phplex' not 'lexer'. Importing 'from phply import lexer' will fail.
fix
Use 'from phply import phplex'.
affects: all
gotchaThe parser module is called 'phpparse' not 'parser'. Importing 'from phply import parser' will fail.
fix
Use 'from phply import phpparse'.
affects: all
deprecatedThe 'make_parser()' function returns a LALR(1) parser. In some versions, parsing with case sensitivity may differ. Always pass a lexer to parse() to avoid confusion.
fix
Use 'parser = phpparse.make_parser()' then 'parser.parse(code, lexer=phplex.lexer)'.
affects: >=1.2
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ply'
PLY is a required dependency but not automatically installed.
fix
Run 'pip install ply'.
ImportError: cannot import name 'lexer' from 'phply'
Incorrect import path; lexer is actually in 'phplex'.
fix
Use 'from phply import phplex' instead.
AttributeError: module 'phply' has no attribute 'phpast'
Trying 'import phply' then 'phply.phpast', but phpast is a submodule.
fix
Use 'from phply import phpast'.
Upgrade
Version history
1.2.6latest on PyPI · released Jan 6, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Amazon
1
Resources
phply — pip install phply · libregistry