Skip to main content

Python client for Run:ai REST API

Project description

runapy

This project provides a Python client 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

Requirements:

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

Client

RunaiClient is the only class required to interact with the Run:ai REST API

from runai.client import RunaiClient

client = RunaiClient(
            realm="myorgrealm",
            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
realm string Required: Can be obtained from the UI login screen at your Run:ai domain app.run.ai -> app.run.ai/auth/realms/
client_id string Required: The Run:ai application name
client_secret string Required: The Run:ai application password
runai_base_url string Required: The URL used to access Run:ai UI
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 cluster:
    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 RuaniClient exposes object controllers for all API endpoints. For example, to access projects:

from runai.client import RunaiClient

client = RunaiClient(
            realm="myorgrealm",
            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

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 examples, check the existing examples here
Feel free to copy and run them as is, modify them as you wish, 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

runapy-0.3.0.tar.gz (14.6 kB view details)

Uploaded Source

Built Distribution

runapy-0.3.0-py3-none-any.whl (14.8 kB view details)

Uploaded Python 3

File details

Details for the file runapy-0.3.0.tar.gz.

File metadata

  • Download URL: runapy-0.3.0.tar.gz
  • Upload date:
  • Size: 14.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for runapy-0.3.0.tar.gz
Algorithm Hash digest
SHA256 9db6b8e5506074e182d053dbe47b5bae8e38975e6ae89a689ce44aadc529faec
MD5 dcc286c9b2996635f6847fd448ed5e97
BLAKE2b-256 c6325abf03017c8f71ec8dd5ceac3ce9a67beae53845b9d85c1ee1013075b851

See more details on using hashes here.

File details

Details for the file runapy-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: runapy-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 14.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.12.4 Darwin/23.5.0

File hashes

Hashes for runapy-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b711fd9e496f966dab4cab1c050ed3f553bceb53acb5276592314ee2370ffbee
MD5 cc0376e1108f95d1c52f410ea9e2ec28
BLAKE2b-256 c8791dd9f592d6cc2f612d4bbc5414e287772a1a6088a9a07c70c7a1c8522edd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page