Python Now Integrates Mojo Code for Enhanced Performance and Flexibility

Brad Larson, the product manager at AI company Modular, announced that users can now invoke Mojo code within Python. Mojo is a superset of Python that offers enhanced features for high-performance computing, taking advantage of modern accelerators.

This programming language was introduced in 2023 by Chris Lattner, the creator of the Swift programming language, as part of his work at Modular.AI.

The Python compatibility section in the Mojo manual has been updated to include a dedicated document covering how to call Mojo from Python. Developers have added some new examples to the Modular GitHub repository: a «hello world» example that demonstrates how to transition from Python to Mojo and back, and another example showing how Mojo code utilizing a GPU can be invoked from Python. These scripts can be utilized through various installation methods for MAX (Modular Accelerated Xecution platform), an integrated set of AI computing tools, and the Mojo compiler, which can be installed via pip (`pip install modular` or `pip install max`) or with Conda through Magic or Pixi.

«We believe that the selective migration of performance bottlenecks in Python code to fast Mojo (especially Mojo running on accelerators) will unlock entirely new applications,» wrote Larson.

He encouraged everyone to review the list of current limitations to avoid bugs and duplicate reports on known issues.

«We’re genuinely excited to see what you will create with this new functionality, and we look forward to your feedback on how to improve it further,» Larson concluded.

Thanks to its open license, Mojo can be freely used on any device for any research, amateur, or educational project. Additionally, the Mojo SDK toolkit is available, enabling the compilation of AI projects on local systems.

In the latest TIOBE programming language rankings, «fast» languages that allow for large-scale data processing in scenarios where hardware might not meet growing demands have started to rise. Mojo is attempting to break into the top 50.