Skip to content

18 · Modules

Python · CPython

Run Python in process with native imports and typed conversion. Windows with CPython 3.12 is verified; a compatible interpreter and native package dependencies are required.

On this page

Run locally with the matching plugin and runtime. These examples do not run in the browser playground.

Python / CPython.

23-extern-python.zolo
// In-process CPython: ordinary Zolo headers, native Python bodies.

use plugin python::{python as py}

extern py fn add(a: int, b: int) -> int {
    # Braces in comments stay inside Python: } {
    return a + b
}

extern py {
    fn normalize(text: str) -> str {
        return text.strip().lower()
    }

    fn factorial(n: int) -> int {
        result = 1
        for value in range(2, n + 1):
            result *= value
        return result
    }
}

let original = "  Zolo  "
let clean: str = extern py {
    return original.strip().upper()
}
let greeting: str = extern py { return f"Hi {original.strip()}" }

extern py fn native_import(value: float) -> float {
    import math
    return math.sqrt(value)
}

extern py fn literal() -> str {
    value = '''Braces { } and "quotes"'''
    return value
}

print(add(20, 22))
print(normalize(original))
print(factorial(5))
print(clean)
print(greeting)
print(native_import(81.0))
print(literal())

// expected:

// 42

// zolo

// 120

// ZOLO

// Hi Zolo

// 9

// Braces { } and "quotes"

Requires the Zolo CLI/host — open in the playground or run locally.

Preparation and deployment

Source-free packaging can retain prepared foreign artifacts, but does not remove runtime or platform dependencies. VM, native and LLVM hosting are covered; foreign bindings reject unsupported WebAssembly targets. The recent provider acceptance covers Windows x64. Python acceptance specifically covers CPython 3.12; other platforms need their own verification.

Reference overview

Global index

Find your way through Zolo

Try an idea

Start here

9 results

9 results

enespt-br