Skip to main content

Automated Python to Mojo code translation

Project description

py2mojo

Automated Python to Mojo code translation

A tool to automatically convert Python code to the new Mojo programming language.

Installation

pip install py2mojo

Usage

You can read the usage by running py2mojo --help:

 py2mojo --help
usage: py2mojo [-h] [--inplace] [--extension {mojo,🔥}] [--convert-def-to-fn | --no-convert-def-to-fn] [--convert-class-to-struct | --no-convert-class-to-struct] filenames [filenames ...]

positional arguments:
  filenames

options:
  -h, --help            show this help message and exit
  --inplace             Rewrite the file inplace
  --extension {mojo,🔥}  File extension of the generated files
  --convert-def-to-fn, --no-convert-def-to-fn
  --convert-class-to-struct, --no-convert-class-to-struct

Examples:

 py2mojo myfile.py
 py2mojo mypackage/*.py

⚠ Disclaimer

Please be aware that the Mojo programming language is still in its nascent stages of development. As with any young language, there might be frequent updates, changes, and unforeseen quirks in its syntax and behavior. There will probably be instances where the conversion might not work and may require manual adjustments.

So, consider this tool as experimental. Please do not trust the generated code and double-check it.

Implementation details

This uses a similar approach to the pyupgrade tool, using the AST parser to analyze the Python code and replace some parts of it with the equivalent Mojo code.

As Mojo is a superset of Python, non-replaced logic should be also a valid Mojo code.

Contributing

How to install it locally

  1. Fork the repository

  2. Clone your fork:

git clone git@github.com:youraccount/py2mojo.git
  1. Install it locally:
cd py2mojo
pip install -e .

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

py2mojo-0.0.1.tar.gz (9.8 kB view details)

Uploaded Source

Built Distribution

py2mojo-0.0.1-py3-none-any.whl (9.3 kB view details)

Uploaded Python 3

File details

Details for the file py2mojo-0.0.1.tar.gz.

File metadata

  • Download URL: py2mojo-0.0.1.tar.gz
  • Upload date:
  • Size: 9.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for py2mojo-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6ec368301ceebf3385d65eaef221e72f1420e36bdd7410fccdec1cba6dc39ebe
MD5 5ee23b1bfafecd45c11ba0ba4293be80
BLAKE2b-256 cdea147a21ec75a634cf275e548c040f4de80b5e1e150799813dceabe5a935ef

See more details on using hashes here.

File details

Details for the file py2mojo-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: py2mojo-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 9.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.4

File hashes

Hashes for py2mojo-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c6bd23c1b530c89eab9a260de1afc4d9c8c24d0b30f84d1999b9ee43dd5d6cc2
MD5 78bb68dbef5e558a32dbdd0ea87376d9
BLAKE2b-256 ddd62f41800c21689eb2f164f324415b1432363ade3ff495e8ca3b19c42a32e7

See more details on using hashes here.

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