Prefect-Ray

0.4.5 · active · verified Thu Apr 16

Prefect-Ray provides integrations for the Prefect workflow orchestration framework with the Ray distributed execution framework. It enables Prefect flows to run tasks in parallel using Ray, either by creating a temporary local Ray instance or connecting to an existing remote one. The library is actively maintained and currently at version 0.4.5, with its own versioning separate from the main Prefect library.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to define a Prefect flow and tasks, then configure the flow to use the `RayTaskRunner`. By default, a temporary local Ray instance is created. You can also specify an `address` to connect to an existing Ray cluster.

import time
from prefect import flow, task
from prefect_ray.task_runners import RayTaskRunner

@task
def shout(number: int):
    time.sleep(0.5)
    print(f"#{number}")

@flow(task_runner=RayTaskRunner())
def count_to(highest_number: int):
    # Tasks are submitted to Ray for parallel execution
    shout.map(range(highest_number)).wait()

if __name__ == "__main__":
    count_to(10)
    # Example of connecting to an existing Ray instance:
    # count_to(10, task_runner=RayTaskRunner(address="ray://localhost:10001"))

view raw JSON →