# Python API for creating Ray autoscaling cluster?

**URL:** <https://discuss.ray.io/t/python-api-for-creating-ray-autoscaling-cluster/1980>\
**Category:** Ray Clusters\
**Created:** [April 29, 2021, 5:54pm UTC](https://discuss.ray.io/t/python-api-for-creating-ray-autoscaling-cluster/1980 "2021-04-29T17:54:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jennakwon06](https://avatars.discourse-cdn.com/v4/letter/j/b19c9b/32.png) [@jennakwon06](https://discuss.ray.io/u/jennakwon06)\
**Post date:** [April 29, 2021, 5:54pm UTC](https://discuss.ray.io/t/python-api-for-creating-ray-autoscaling-cluster/1980/1 "2021-04-29T17:54:42Z")

</div>

Hello!

I was wondering if there’s a way to, or if there’s a plan to, supporting Python APIs for spinning up multi-node autoscaling Ray clusters.

I’m looking for something like…

> script.py:

```auto
cluster_info = ray.create_cluster("cluster.yaml") # call blocks until cluster is instantiated
head_node_ip = cluster_info["head_node_ip"]
ray.init(address="auto") # connect to cluster created in this script 

# do things with Ray API so that compute happens on the distributed Ray cluster

```

---

<div class="post-metadata">

**Author:** ![lshao-ts](https://avatars.discourse-cdn.com/v4/letter/l/5f8ce5/32.png) [@lshao-ts](https://discuss.ray.io/u/lshao-ts)\
**Post date:** [September 24, 2021, 9:53pm UTC](https://discuss.ray.io/t/python-api-for-creating-ray-autoscaling-cluster/1980/2 "2021-09-24T21:53:43Z")

</div>

The following works:

- In a python subprocess, run `ray.scripts.scripts.start` with the arguments as if you call `ray start --head` in the commandline. Add the `--block` flag to make it blocking in the sub process.
- In the main process, wait for the `ray_current_cluster` file to appear in the temp directory. It contains the ip and port to connect to ray. The temp directory can be specified when you call `ray start --head` above.
- Read the `ray_current_cluster` file and then call `ray.init(address=...)`.
- Run your workflow.
- Call `ray.shutdown()` in the main process, then kill the subprocess.
