Skip to main content

PHP to Python transpiler.

Project description

php2py

image

PHP to Python transpiler.

  • Free software: GNU General Public License v3

Use cases

  • Helping port PHP code to Python (provides a first pass, which can then be manually edited).

Features

  • Translates a subset of PHP to Python.

Install

  • You need PHP and composer installed on your system.
  • You need Python 3.10+.

For development

  • From a git checkout, run
poetry shell
poetry install
composer install

For actual use

This should work:

pipx install php2py

Architecture

  • Front-end (PHP parser): uses an external PHP parser (nikic/php-parser) to parse PHP code and build an AST.
  • Back-end (Python generator): uses the AST to generate Python code, via pattern matching.
  • Python code is generated from AST using the unparse from the stdlib.

TODO

  • Add test cases (real programs) and make sure they pass.
  • Make a runtime / stdlib of common PHP functions in Python.
  • Cleanup.

Prior art

Contributing

I don't have time to work on this project ATM, but I'm happy to review pull requests.

If you are a student (or a group of students) in a computer science or engineering program, and you want to work on this, please contact me (mailto:sf@abilian.com).

If you think this project can be useful for your company, you can support the development effort through a sponsorship via my company, Abilian: https://abilian.com/.

Credits

This package was created with Cruft and the abilian/cookiecutter-abilian-python project template.

This project uses the nikic/php-parser PHP parser (in PHP).

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

php2py-0.2.0.tar.gz (28.8 kB view hashes)

Uploaded Source

Built Distribution

php2py-0.2.0-py3-none-any.whl (20.0 kB view hashes)

Uploaded Python 3

Supported by

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