Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/boblio-max/origin/llms.txt

Use this file to discover all available pages before exploring further.

Origin is built on top of Python, and the py { } block makes that relationship explicit and useful. Whenever you need a Python library, a language feature that Origin doesn’t expose directly, or a utility function you’d rather write in standard Python, you can drop into Python at any point in your .or script with no boilerplate and no context switching. Code inside py { } is passed verbatim to Python’s exec() and shares the same variable scope as the rest of your Origin program.

Syntax

py {
    # Any valid Python code goes here
    x = 10
    print("Hello from Python!")
}
Everything between the opening { and closing } is treated as raw Python. The Origin lexer and parser do not interpret anything inside the braces — only the surrounding py keyword and the brace delimiters are consumed by Origin’s grammar. Nested { and } are handled correctly: the parser tracks brace depth so that Python dict literals, set comprehensions, and similar constructs do not accidentally close the block early.

How It Compiles

When the Origin parser encounters py { ... }, it captures the content between the braces as a raw string and produces a PyNode AST node. The interpreter’s code generator then emits that string verbatim with no transformation whatsoever:
# interpreter.py — PyNode handling
elif isinstance(node, PyNode):
    return node.code
There is no wrapping, no indentation adjustment at the block level, and no name mangling. The Python code you write is exactly the Python code that runs.

Scope Sharing

Origin variables and Python variables share the same execution globals dictionary. This means you can freely read and write Origin variables from inside a py block, and any names you define in a py block are immediately available to subsequent Origin statements.
let base: int = 100

py {
    # Read an Origin variable, compute in Python, write back
    result = base * 3.14159
    label = "area"
}

# 'result' and 'label' are now available as Origin variables
print result
print label
The assignment to result inside the py block is visible to print result below it because both operate on the same globals dict.

Example: Standard Library Access

The idiomatic way to reach any Python standard library module is to import it inside a py block:
py {
    import math
    import os
    print("Python process ID:", os.getpid())
    print("Sine of 90 degrees:", math.sin(math.pi/2))
}
After the py block runs, math and os are bound in the shared globals and can be referenced by subsequent py blocks in the same script.

Example: Define a Python Function, Call It from Origin

You can define a Python function inside a py block and then call it from Origin code:
py {
    def clamp(value, lo, hi):
        return max(lo, min(hi, value))
}

let angle: int = 250
let safe_angle: int = clamp(angle, 0, 180)
print safe_angle   # prints 180
The function clamp is defined in the shared globals by the py block and is immediately callable as an expression anywhere in the Origin script that follows.

The exec Keyword

Origin also provides an exec keyword for running a separate Origin script embedded as a string literal. It is entirely distinct from py { }:
exec "let x: int = 5\nprint x"
When the interpreter encounters exec, it writes the string content to a temporary file (temp_exec.py) and then invokes runner.py on that file via subprocess.run(). The string is interpreted as Origin source code — it goes through the full lex → parse → generate → execute pipeline in a subprocess. It is not a shell command and does not invoke a system shell.
# Correct: the string is Origin source code
exec "print 42"

# Incorrect: shell syntax is not valid here
# exec "echo Hello"   # this would fail — echo is not an Origin keyword
Use exec when you need to run a fragment of Origin code dynamically from a string. For shell commands or system utilities, use a py { } block with Python’s subprocess module directly:
py {
    import subprocess
    subprocess.run(["echo", "Hello from the shell"])
}
py blocks unlock the entire Python package ecosystem. Install any third-party library (numpy, OpenCV, Pillow, requests, etc.) with pip and import it directly inside a py block — no special Origin integration required.
py {
    import numpy as np
    matrix = np.array([[1, 2], [3, 4]])
    print("Determinant:", np.linalg.det(matrix))
}
Python code inside py blocks bypasses Origin’s type system entirely. Origin performs static type checking on let declarations and AssignNode values, but nothing inside a py block is inspected by the type checker. A type mismatch between a Python-assigned variable and a later Origin let declaration will not be caught until the code actually executes at runtime.
Python indentation rules apply inside py blocks. The block content is passed directly to exec(), so Python’s significant-whitespace rules are fully in effect. Indent function bodies, if branches, loops, and class definitions exactly as you would in a standard .py file. The outer py { } braces are Origin syntax and do not themselves create an indentation level.

Build docs developers (and LLMs) love