Skip to main content

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] [--float-precision {32,64}]
               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
  --float-precision {32,64}

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 .

Metadata

Release files for py2mojo 0.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for py2mojo 0.0.2
File Size Uploaded Provenance
py2mojo-0.0.2.tar.gz 10.8 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for py2mojo 0.0.2
File Interpreter ABI Platform
py2mojo-0.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 21.1 kB

Release files / py2mojo-0.0.2.tar.gz

Download URL py2mojo-0.0.2.tar.gz
Size 10.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f1e621706db9a4ecfb05b17b9cb849f8bd0518f77b6492a375ce26c76db2414a
BLAKE2b-256 checksum
How to use checksums
96f7a879817023aeb9e96d096826eca727bbd9adb45cca43c9713c5c918a0266
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Release files / py2mojo-0.0.2-py3-none-any.whl

Download URL py2mojo-0.0.2-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
162ceaee5fd4b5128612e19965c800d985ae67f720ec1ad5fd6eda413459d376
BLAKE2b-256 checksum
How to use checksums
9dd06e36af374f638e4c5b987991a031b6f57f6aa7e9af441dd690bb97c688e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.5

Security for py2mojo 0.0.2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.0.2 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page