Python interoperability
Imports under the py. namespace use a Python 3 subprocess. Other imports use native or local Genzimnify modules.
Import a Python library
pull up py.math as pymath
yap(call up pymath.sqrt(81) yo)The alias binds the imported module to pymath. outta imports are also supported:
outta py.json pull up dumps
yap(call up dumps({"ready": nocap}, sort_keys be nocap) yo)
Third-party packages
python3 -m pip install numpypull up py.numpy as np
let average be call up np.mean([10, 20, 30]) yo
yap(average)The bridge uses the first python3 or python executable on PATH. On Windows it also recognizes the py -3 launcher.
Value conversion
| Genzimnify | Python |
|---|---|
ghost | None |
| truth, num, drip, text | bool, int, float, str |
| stack, crew, squad | JSON-style list |
| map with text keys | dict |
NumPy scalars and arrays are converted through item() and tolist(). Other Python objects return a map containing __python_type__ and __python_repr__.
Module selection
pull up math loads Genzimnify’s native module. pull up py.math starts the Python bridge. Programs without py.* imports do not start Python.
Current limitations
Each bridged call is isolated. JSON-compatible values cross the boundary, but live Python object identity is not preserved between calls. For long-lived Python objects, build a small Python function that performs the operation and returns plain data.
Source conversion (2.0.3 preview)
gzim convert main.gzim --to py
gzim convert main.py --to gzim -o converted.gzimThese commands translate source files rather than calling the Python bridge. The default output is a sibling file with the target extension. Existing outputs require --force; the source cannot be replaced. Python export reuses the existing emitter. Python import uses an embedded AST converter and requires Python 3.8+ on PATH (with py -3 as a Windows fallback). Input code is parsed and compiled for validation but never executed.
Supported Python subset
- Single-name and subscript assignment, arithmetic augmented assignment, numeric/string/boolean/None literals, list/tuple/set/dictionary literals, and indexing.
- Arithmetic, boolean operators, single comparisons, membership tests, if/elif/else, while, single-name for loops, break, continue, and pass.
- Ordinary functions, positional or named calls, default parameters, nested functions, and return. Assignment creates mutable
letbindings. - Selected builtin calls and container methods listed below. Builtin shadowing is resolved by lexical scope. Variables and parameters that conflict with Genzimnify names are escaped with
_py_; existing names with that prefix are also escaped to avoid collisions.
Builtin and method forms
Only positional arguments are accepted for builtin and method calls. Keyword arguments are supported for user functions. Passing a builtin or method as a value or callback is not supported.
| Python call | Preview support |
|---|---|
print, input | print accepts positional values; input accepts zero or one argument. No sep/end/file/flush options. |
range, enumerate, zip | range takes 1–3 arguments; enumerate takes 1–2; zip takes positional iterables. Native results are eager. |
int, float, str, bool, list, tuple, set | Zero or one argument. Numeric and text conversions follow native runtime semantics. |
dict | Empty dict() only; use dictionary literals for populated maps. |
len, sum, min, max, abs, sorted | One argument only; no start, key, default, or reverse options. |
| Container methods | append, extend, insert, remove, reverse, pop, get, keys, values, items, join, startswith, endswith, replace. Available forms and behavior depend on the native receiver type. |
Preview boundaries
Imports, classes, decorators, annotations, async, generators, comprehensions, f-strings, slices, unpacking, chained assignment/comparisons, identity comparisons, loop else, exception handling, global/nonlocal, non-ASCII identifiers, and advanced function parameters are rejected. Unsupported constructs report the original file and line, and no partial output is saved. Generated Genzimnify is parsed and semantically checked before writing.
Comments, shebangs, encoding declarations, and original whitespace are not preserved. Output uses UTF-8 and four-space indentation. This is a migration aid, not full Python compatibility: native integers are signed 64-bit, text operations are byte-oriented, iteration is eager, and collection/method behavior can differ. Review and test converted programs. Arbitrary files, including exports using unsupported features, are not guaranteed to convert back; source text and lock bindings do not round-trip losslessly.