Version: 1.1.0
Calling Python from Mojo
Calling Python from Mojo is an ordinary import plus method calls on PythonObject.
Essentials
- Import
Pythonfrom the standard library. - Keyword calls use Python's names.
- Convert a Mojo
Listor string when the Python API wants a concrete object. - Exceptions raised on the Python side surface as Mojo errors.
Example
from python import Python
def main() raises:
var py = Python.import_module("builtins")
py.print("hello from python")
Keep in mind
Check types at the boundary. A PythonObject will happily hold almost anything until you use it.