Updated on 2026-11-06 GMT+08:00

runtime_env

The runtime_env is used to declare the runtime environment required for UDF execution, including the Python version, PyPI dependencies, and environment variables. This configuration is serialized as a JSON string and stored in the parameters.runtime_env field of LakeFormation. The Aura engine prepares the environment according to this configuration when running the UDF.

Function

  • Ensuring execution: The third-party packages and Python versions required by the UDF are installed on the engine as declared, preventing the issue of "local execution success but remote execution failure."
  • Version control: The Python version (3.10/3.11) and specified package version can be fixed to ensure a consistent runtime environment.
  • Cross-end synchronization: The environment configuration is persisted with the function metadata and is bound to the function's lifecycle.

When to Use

Table 1 Scenario

Scenario

Usage

UDF depends on a third-party Python package.

Declare the package name (for example, ["numpy"]) in pypi/pip.

Need to specify a Python version

Set python_version (only 3.11 or 3.10 is supported).

Need to inject runtime environment variables

Set env_vars.

No special dependency

Pass None. The SDK constructs the default environment (python_version=3.11).

Construction Methods

runtime_env accepts the following three forms, which the SDK internally unifies into a RuntimeEnv object:

Table 2 Construction methods

Input Form

Example

Description

JSON string

'{"python_version": "3.11", "pypi": ["numpy"]}'

Parsed by json.loads.

Mapping/dict

{"python_version": "3.11", "pypi": ["numpy"]}

Directly updated into the internal data structure.

None

-

Constructs the default RuntimeEnv with python_version set to 3.11.

Common Keys

Table 3 Common keys

Key

Type

Description

python_version

str

Python version. Only 3.11 (default) or 3.10 is supported. Passing other versions raises a ValueError.

pypi/pip

list[str]

List of PyPI dependencies. Merged by deduplicating package names.

env_vars

dict

Runtime environment variables.

Default Values and Verification Behavior

  • When runtime_env is None, the SDK constructs an empty RuntimeEnv and automatically sets python_version to 3.11.
  • If runtime_env provides a python_version, the SDK verifies its value. A ValueError is raised if the value is not 3.11 or 3.10.
  • RuntimeEnv is a mutable mapping (like a dictionary) that supports the to_dict(), to_json(), and merge(other) methods. The merge method uses a deep merge strategy: Dictionaries are merged recursively. Lists are merged with deduplication (for keys like pypi/pip/dependencies, deduplication is performed based on package names). For scalar conflicts, the left value takes precedence.

Return Value

Returns a Function object containing the version_id assigned by LakeFormation, resource_uris (OBS package addresses), and parameters (metadata such as the signature and runtime environment).