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
| Name | Type | Description |
|---|---|---|
| script | pathlib.Path | Path to the Python script to run. |
| cpu | int = 4 | Number of CPUs to request. |
| memory | str = "16Gi" | Memory to request, e.g. "16Gi". |
| gpu | int = 0 | Number of GPUs to request. |
| gpu_type | str = "T4" | GPU accelerator type: T4, A100, H100, L4, etc. Only used when gpu > 0. |
| image | Union[Image, List[str], None] = None | Container 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. |
| timeout | int = 3600 | Task timeout in seconds. |
| extra_args | Optional[List[str]] = None | Extra arguments passed to the script. |
| queue | Optional[str] = None | Flyte queue / cluster override. |
| wait | bool = False | If True, block until execution completes before returning. |
| name | Optional[str] = None | Run name. If omitted, a random name is generated. |
| debug | bool = False | If 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_dir | Optional[str] = None | The output directory for the script. |
| include_files | Optional[List[str]] = None | Extra 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
| Type | Description |
|---|---|
Run | A flyte.remote.Run handle for the remote execution. |