Skip to content

Python Libraries

Wyn can compile your code into shared libraries that Python can call directly.

Quick Start

Write a Wyn library:

wyn
// mathlib.wyn
fn add(a: int, b: int) -> int {
    return a + b
}

fn factorial(n: int) -> int {
    if n <= 1 { return 1 }
    return n * factorial(n - 1)
}

Build with --python:

sh
wyn build mathlib.wyn --python

This produces:

  • libmathlib.dylib (or .so on Linux, .dll on Windows)
  • mathlib.py — auto-generated Python wrapper

Use from Python:

python
from mathlib import add, factorial

print(add(2, 3))           # 5
print(factorial(20))        # 2432902008176640000

Type Mapping

Wyn TypePython TypeNotes
intint64-bit integer
floatfloat64-bit double
stringstrAuto encode/decode UTF-8
boolboolTrue/False

Flags

FlagOutput
--sharedShared library only
--pythonShared library + Python wrapper

Notes

  • Functions named main are excluded from the wrapper
  • Struct methods (with self) are excluded
  • String arguments are automatically encoded/decoded

MIT License