Skip to main content

run_python_script

Package and run a Python script on a remote Flyte cluster.

def run_python_script(
script: pathlib.Path,
cpu: int = 4,
memory: str = "16Gi",
gpu: int = 0,
gpu_type: str = "T4",
image: Union[Image, List[str], None] = None,
timeout: int = 3600,
extra_args: Optional[List[str]] = None,
queue: Optional[str] = None,
wait: bool = False,
name: Optional[str] = None,
debug: bool = False,
output_dir: Optional[str] = None,
include_files: Optional[List[str]] = None
) - > Run

Package and run a Python script on a remote Flyte cluster. Bundles the script into a Flyte code bundle and executes it remotely with the requested resources. Unlike interactive_mode (which pickles the task), this approach uses an InternalTaskResolver so the task can be properly debugged with debug=True. Project and domain are read from the init config (set via flyte.init() or flyte.init_from_config()), consistent with flyte.run().

Parameters

NameTypeDescription
scriptpathlib.PathPath to the Python script to run.
cpuint = 4Number of CPUs to request.
memorystr = "16Gi"Memory to request, e.g. "16Gi".
gpuint = 0Number of GPUs to request.
gpu_typestr = "T4"GPU accelerator type: T4, A100, H100, L4, etc. Only used when gpu > 0.
imageUnion[Image, List[str], None] = NoneContainer image to use. Accepts either: - A flyte.Image object for full control over the image. - A list[str] of pip package names to install on top of the default Debian base image (e.g. ["torch", "transformers"]). - None to use a plain Debian base image.
timeoutint = 3600Task timeout in seconds.
extra_argsOptional[List[str]] = NoneExtra arguments passed to the script.
queueOptional[str] = NoneFlyte queue / cluster override.
waitbool = FalseIf True, block until execution completes before returning.
nameOptional[str] = NoneRun name. If omitted, a random name is generated.
debugbool = FalseIf True, run the task as a VS Code debug task, starting a code-server in the container so you can connect via the UI to interactively debug/run the task.
output_dirOptional[str] = NoneThe output directory for the script.
include_filesOptional[List[str]] = NoneExtra paths or glob patterns to bundle alongside the script. Relative entries anchor at the script's directory; absolute paths pass through unchanged. Example: ["*.py", "configs/settings.yaml"].

Returns

TypeDescription
RunA flyte.remote.Run handle for the remote execution.