Chris Lattner mentioned that Python can actually call Mojo code now. I love this idea (!) as I'm definitely in the market for a simple compiled language that can offer Python some really fast functions. So I gave it a quick spin Setup The setup is much simpler than I remember it, you can use uv for it now. uv pip install modular --index-url https://dl.modular.com/public/nightly/python/simple/ After that you can declare a .mojo file that looks like this: # mojo_module.mojo from python import PythonObject from python.bindings import PythonModuleBuilder import math from os import abort @export fn PyInit_mojo_module() -> PythonObject: try: var m = PythonModuleBuilder("mojo_module") m.def_function[factorial]("factorial", docstring="Compute n!") return m.finalize() except e: return abort[PythonObject](String("error creating Python Mojo module:", e)) fn factorial(py_obj: PythonObject) raises -> PythonObject: # Raises an exception if `py_obj` is not convertible to a Mojo `Int`. var n = Int(py_obj) var result = 1 for i in range(1, n + 1): result *= i return result And you can then load it from Python via: # main.py import max.mojo.importer import os import sys import time import math sys.path.insert(0, "") import mojo_module start = time.time() print(mojo_module.factorial(10)) end = time.time() print(f"Time taken: {end - start} seconds for mojo") start = time.time() print(math.factorial(10)) end = time.time() print(f"Time taken: {end - start} seconds for python") This was the output: 3628800 Time taken: 3.0279159545898438e-05 seconds for mojo 3628800 Time taken: 5.0067901611328125e-06 seconds for python This all works, but at the time of making this blogpost I was able to spot some rough edges. If I increase the factorial number to 100 then the output changes. 0 Time taken: 2.7894973754882812e-05 seconds for mojo 18826771768889260997437677024916008575954036487149242588759823150835315633161359886688293288949592313364640544593005774063016191934138059781888345755854705552432637...
First seen: 2025-06-23 04:02
Last seen: 2025-06-24 01:09