Calling Python from Seq

Calling Python from Seq is possible in two ways:

  • from python import allows importing and calling Python functions from existing Python modules.

  • @python allows writing Python code directly in Seq.

In order to use these features, the SEQ_PYTHON environment variable must be set to the appropriate Python shared library:

export SEQ_PYTHON=/path/to/

For example, with a brew-installed Python 3.9 on macOS, this might be


Note that only Python versions 3.6 and later are supported.

from python import

Let’s say we have a Python function defined in

def multiply(a, b):
    return a * b

We can call this function in Seq using from python import and indicating the appropriate call and return types:

from python import mymodule.multiply(int, int) -> int
print(multiply(3, 4))  # 12

(Be sure the PYTHONPATH environment variable includes the path of!)


Seq programs can contain functions that will be executed by Python via pydef:

def multiply(a: int, b: int) -> int:
    return a * b

print(multiply(3, 4))  # 12

This makes calling Python modules like NumPy very easy:

def myrange(n: int) -> List[int]:
    from numpy import arange
    return list(arange(n))

print(myrange(5))  # [0, 1, 2, 3, 4]