What is Ray?


Ray provides a simple, universal API for building distributed applications.

Ray accomplishes this mission by:

  1. Providing simple primitives for building and running distributed applications.

  2. Enabling end users to parallelize single machine code, with little to zero code changes.

  3. Including a large ecosystem of applications, libraries, and tools on top of the core Ray to enable complex applications.

Ray Core provides the simple primitives for application building.

On top of Ray Core are several libraries for solving problems in machine learning:

There are also many community integrations with Ray, including Dask, MARS, Modin, Horovod, Hugging Face, Scikit-learn, and others. Check out the full list of Ray distributed libraries here.

Getting Started with Ray

Check out A Gentle Introduction to Ray to learn more about Ray and its ecosystem of libraries that enable things like distributed hyperparameter tuning, reinforcement learning, and distributed training.

Ray provides Python and Java API. And Ray uses Tasks (functions) and Actors (Classes) to allow you to parallelize your code.

# First, run `pip install ray`.

import ray

def f(x):
    return x * x

futures = [f.remote(i) for i in range(4)]
print(ray.get(futures)) # [0, 1, 4, 9]

class Counter(object):
    def __init__(self):
        self.n = 0

    def increment(self):
        self.n += 1

    def read(self):
        return self.n

counters = [Counter.remote() for i in range(4)]
[c.increment.remote() for c in counters]
futures = [c.read.remote() for c in counters]
print(ray.get(futures)) # [1, 1, 1, 1]

First, add the ray-api and ray-runtime dependencies in your project.

import io.ray.api.ActorHandle;
import io.ray.api.ObjectRef;
import io.ray.api.Ray;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

public class RayDemo {

  public static int square(int x) {
    return x * x;

  public static class Counter {

    private int value = 0;

    public void increment() {
      this.value += 1;

    public int read() {
      return this.value;

  public static void main(String[] args) {
    // Intialize Ray runtime.
      List<ObjectRef<Integer>> objectRefList = new ArrayList<>();
      // Invoke the `square` method 4 times remotely as Ray tasks.
      // The tasks will run in parallel in the background.
      for (int i = 0; i < 4; i++) {
        objectRefList.add(Ray.task(RayDemo::square, i).remote());
      // Get the actual results of the tasks with `get`.
      System.out.println(Ray.get(objectRefList));  // [0, 1, 4, 9]

      List<ActorHandle<Counter>> counters = new ArrayList<>();
      // Create 4 actors from the `Counter` class.
      // They will run in remote worker processes.
      for (int i = 0; i < 4; i++) {

      // Invoke the `increment` method on each actor.
      // This will send an actor task to each remote actor.
      for (ActorHandle<Counter> counter : counters) {
      // Invoke the `read` method on each actor, and print the results.
      List<ObjectRef<Integer>> objectRefList = counters.stream()
          .map(counter -> counter.task(Counter::read).remote())
      System.out.println(Ray.get(objectRefList));  // [1, 1, 1, 1]

You can also get started by visiting our Tutorials. For the latest wheels (nightlies), see the installation page.

Getting Involved

Ray is more than a framework for distributed applications but also an active community of developers, researchers, and folks that love machine learning. Here’s a list of tips for getting involved with the Ray community:

  • Join our community slack to discuss Ray! The community is extremely active in helping people succeed in building their ray applications.

  • Star and follow us on on GitHub.

  • Join our Meetup Group to connect with others in the community!

  • Use the [ray] tag on StackOverflow to ask and answer questions about Ray usage

  • Subscribe to ray-dev@googlegroups.com to join development discussions.

  • Follow us and spread the word on Twitter!

If you’re interested in contributing to Ray, visit our page on Getting Involved to read about the contribution process and see what you can work on!

More Information

Here are some talks, papers, and press coverage involving Ray and its libraries. Please raise an issue if any of the below links are broken, or if you’d like to add your own talk!