---
title: "Ray"
description: "Ray is an open-source framework for scaling Python applications, including distributed compute, machine learning training, and hyperparameter tuning, across clusters of machines."
canonical: "https://motherduck.com/glossary/ray/"
related:
  - title: "Why Use DuckDB for Analytics?"
    url: "https://motherduck.com/blog/six-reasons-duckdb-slaps/"
  - title: "DuckDB breaks the lakehouse? ft. Daniel Beach | EXPLAIN ANALYZE | MotherDuck"
    url: "https://motherduck.com/explain-analyze/0003-duckdb-breaks-the-lakehouse/"
  - title: "DuckLake Architecture Deep Dive: Catalog, Storage, Compute | MotherDuck"
    url: "https://motherduck.com/videos/ducklake-architecture-deep-dive/"
gated_asset:
  title: "DuckLake on MotherDuck"
  url: "https://motherduck.com/product/ducklake/"
---

# Ray

> Ray is an open-source framework for scaling Python applications, including distributed compute, machine learning training, and hyperparameter tuning, across clusters of machines.

## Overview

Ray is a distributed execution framework for Python that makes it straightforward to scale arbitrary Python functions and classes across a cluster. At its core, Ray provides simple primitives — `@ray.remote` tasks and actors — for turning ordinary Python functions and objects into units of work that run in parallel across many CPUs or nodes. On top of that core, the Ray ecosystem includes higher-level libraries: Ray Train for distributed model training, Ray Tune for hyperparameter search, Ray Serve for model serving, and Ray Data for distributed data loading and preprocessing.

## Basic usage

```python
import ray

ray.init()

@ray.remote
def process(x):
    return x * x

futures = [process.remote(i) for i in range(10)]
results = ray.get(futures)
```

Ray handles scheduling these remote calls across available workers, whether that's cores on your laptop or hundreds of nodes in a cluster.

## Where Ray fits versus a query engine

Ray is a general-purpose distributed computing framework, not a SQL engine or a database. It's typically used for machine learning workloads: distributed training, large-scale batch inference, hyperparameter tuning, and reinforcement learning. It differs from analytical engines like DuckDB, which are purpose-built for fast, vectorized SQL and dataframe queries over structured data on a single node. In practice these tools are often complementary in a pipeline: DuckDB (or a warehouse) can be used to select, join, and filter down a large dataset into the feature set actually needed for training, and Ray then takes over to distribute the compute-heavy model training or inference step across a cluster.
