Version: 1.1.0

Python types

PythonObject is the Mojo type that stands for an arbitrary Python value. Convert at the edges.

Essentials

  • Integers and floats convert to Int and Float64 when you ask.
  • Strings convert to String.
  • Lists and dicts stay objects until you copy them into Mojo collections.
  • None is a real Python value, not Mojo's uninitialized state.

Example

from python import PythonObject

def as_int(obj: PythonObject) raises -> Int:
    return Int(obj)

Keep in mind

Every conversion is explicit because Python values do not have Mojo's static type.