skillfed

phply

Lexer and parser for PHP source implemented using PLY

phply v1.2.6 183.8K downloads/30d#10,058 on PyPI367
Permissive license BSD Abandoned released

What it is and what it does

phply is a PHP parser built on ply, a lexer/parser generator toolkit. It tokenizes PHP source code and builds abstract syntax trees that represent the program structure. The package includes a lexer that matches PHP's standard token set and a parser covering most of the PHP grammar, plus utility scripts to dump ASTs as JSON or convert PHP templates to Jinja2.

The parser is designed for analysis and transformation tasks—converting PHP code to Python, running PHP templates in Python environments, or studying how industrial languages handle parsing edge cases. It is not a PHP runtime. The package is in a stable but abandoned state; while it has no known vulnerabilities, it receives no active maintenance and will not track PHP language evolution.

Use it for:

  • Analyze PHP source code structure and generate ASTs for static analysis tools
  • Convert legacy PHP templates to Jinja2 for use in Python web frameworks
  • Build PHP-to-Python code migration or transpilation tools
  • Study parsing techniques for complex, real-world language grammars
  • Extract metadata or patterns from PHP codebases programmatically

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

phply is a lexer and parser for PHP source code that generates abstract syntax trees, enabling PHP code analysis and conversion to other formats like JSON or Jinja2 templates.

Yes, if you need to parse PHP code for analysis or conversion and can accept that the parser may not handle very recent PHP syntax. The low install friction and permissive license make it accessible. No, if you require active maintenance, support for modern PHP versions, or a runtime environment—phply is abandoned and will not evolve with the PHP language.

Install

phply on PyPI

pip

pip install phply

uv

uv add phply

poetry

poetry add phply

Installing phply

Before you install

Installation is straightforward with a single pure-Python dependency (ply). However, the package is abandoned—last commit was 2023-02-20 and no releases in over 1316 days. It will not receive bug fixes or updates for newly discovered PHP syntax or language features.

License in practice

BSD license is permissive, allowing use in both open-source and proprietary projects with minimal restrictions. You must include a copy of the license and retain authorship notices.

Quickstart

pip install phply

from phply.phplex import PhpLexer
from phply.phpparse import PhpParser

lexer = PhpLexer()
parser = PhpParser()
result = parser.parse('<?php echo "hello"; ?>', lexer=lexer.lexer)

Verify before relying

  • Whether the parser handles modern PHP syntax or only older versions
  • Completeness of PHP grammar coverage beyond labels and goto statements
  • Stability and correctness of the Jinja2 conversion tool for real-world templates

Package facts

License BSD (permissive)
Python support not specified
Install friction low — pure-Python wheel
Runtime dependencies 1 — ply
Maintenance abandoned — 1,316 days since the last release
Last repo commit
First released
Downloads 183,782/month — #10,058 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: phply-1.2.6-py2.py3-none-any.whl

Development Status :: 5 - Production/StableEnvironment :: ConsoleIntended Audience :: EducationLicense :: OSI Approved :: BSD LicenseOperating System :: UnixProgramming Language :: PHPProgramming Language :: Python :: 2Programming Language :: Python :: 3

Tags

PHP parser PythonPHP lexer analyzerPHP to AST converterPHP code parsingPHP syntax tree generatorPHP source analysisPLY-based PHP parser
parser-generatorcode-analysislanguage-tools

More Text Processing packages