Python client for Run:ai REST API
Project description
runapy
This project provides a Python client SDK to interact with the Run:ai REST API.
The client offers:
- A single class interface to perform all API actions
- Body schema validation on compilation (with Pydantic)
- Static type checks
- Retry mechanism for resiliency on intermittent network errors
- Debug messages flag
- Automatic token refresh
Requirements
- Run:ai control-plane version 2.18 and above: Required for compatibility with the SDK.
- Python 3.11 and above: Ensures compatibility with the latest Python features and libraries.
- Run:ai Client Application: A client application is needed to generate the credentials required for API access. Create a client application here.
Note on token and permissions
When creating an application, it is important to select the relevant role and scope for the required API actions.
Some API calls may fail with 403 if the application token does not have sufficient permissions.
Installation
runapy is available in PyPi and can be downloaded directly as a python package
pip3 install runapy
It's recommended to install runapy
in a virtual environment to avoid conflicts with other packages.
python3 -m venv myenv
source myenv/bin/activate
pip3 install runapy
Client
RunaiClient
is the only class required to interact with the Run:ai REST API
from runai.client import RunaiClient
client = RunaiClient(
client_id="API",
client_secret="clientsecret",
runai_base_url="https://myorg.run.ai",
cluster_id="513423qx-127t-4yk6-979g-5po843g37e2b",
retries=3,
debug=False
)
Parameter | Type | Description |
---|---|---|
client_id |
string |
Required: The Run:ai application client ID, usually representing the application name |
client_secret |
string |
Required: The client secret associated with the Run:ai application, acting as a password |
runai_base_url |
string |
Required: The base URL for the Run:ai instance your organization uses. Example: https://myorg.run.ai |
retries |
int |
Optional: Number of retries to attempt on each failed API call for 5xx errors. Default is 1 |
cluster_id |
string |
Optional: The ID of the cluster. Default is None |
debug |
bool |
Optional: Debug mode output. Default is False |
If you don't have the cluster_id
, it can be obtained with:
clusters = client.clusters.all()
for cluster in clusters:
cluster_id = cluster["uuid"]
Note - If you have more than one cluster, make sure to save the ids to cluster_ids_list
, and select the relevant cluster_id
Then, configure the client with the cluster id:
client.config_cluster_id(cluster["uuid"])
Note - The cluster_id
must be present in order to use endpoints that have cluster_id
required in payload according to Run:ai REST API.
So make sure to configure the cluster_id before using them.
Note on Controllers
The RunaiClient
exposes object controllers for all API endpoints.
For example, to access projects:
from runai.client import RunaiClient
client = RunaiClient(
client_id="API",
client_secret="clientsecret",
runai_base_url="https://myorg.run.ai",
cluster_id="513423qx-127t-4yk6-979g-5po843g37e2b",
retries=3,
debug=False
)
client.projects.all()
client.projects.all()
returns a list of all projects in a given cluster according to the cluster id of the RunaiClient.
Currently supported controllers:
client.projects
client.node_pools
client.departments
client.access_rules
client.roles
client.users
client.workloads
client.workspace
client.training
client.inference
client.distributed
client.assets.pvc
client.assets.s3
client.assets.git
client.assets.nfs
client.assets.credentials.access_key
client.assets.credentials.password
client.assets.credentials.docker_registry_secret
Each controller exposes the function options()
so you can see which methods are currently availalble for a given controller.
For example:
client.roles.options()
->
['all', 'get', 'get_roles_name_to_id_map']
Controller methods are documented.
Hover on the method parentheses to see the required and optional fields to pass to the function.
Examples
For more practical examples, check the existing examples here:
- How to create, list, patch projects/departments resources in a cluster
- Creating and managing workloads
- Accessing and modifying user roles
- Managing PVC, S3, NFS, Git assets
Feel free to copy and run them as is, modify them as needed, or use them as a reference.
Warranty
This package is not maintained by the Run:ai product team.
For any issues and requests, please open an issue, or contact the authors of this package.
License
This project is licensed under the MIT License. See the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file runapy-0.6.0.tar.gz
.
File metadata
- Download URL: runapy-0.6.0.tar.gz
- Upload date:
- Size: 18.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 554c029e2da3c2d16206eccae9bd4cd4749ce1483e33a78f48a7b4c61fb95ce4 |
|
MD5 | 72b0e52ce61242688db2bb3fa5c4202b |
|
BLAKE2b-256 | 6bc0a9dcd322b50738a6226565bf3215f434b3f56d332820aa17efbf8977df23 |
File details
Details for the file runapy-0.6.0-py3-none-any.whl
.
File metadata
- Download URL: runapy-0.6.0-py3-none-any.whl
- Upload date:
- Size: 18.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.3 CPython/3.12.6 Darwin/23.5.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bfd4fc98d0fd88315c57efb2b88cda380e70e8d49040f5631987c5a2cd685183 |
|
MD5 | 4aa608db8b2be6dd3e5c81920ae57aec |
|
BLAKE2b-256 | 9564816a1a12c5428fd8d419b43f6e42ed6ebc774630fba483e30799bb486183 |