Skip to main content

Python client for sunra.ai

Project description

sunra.ai Python client

This is a Python client library for interacting with ML models deployed on sunra.ai.

Getting started

To install the client, run:

pip install sunra-client

To use the client, you need to have an API key. You can get one by signing up at sunra.ai. Once you have it, set it as an environment variable:

export SUNRA_KEY=your-api-key

Now you can use the client to interact with your models. Here's an example of how to use it:

import sunra_client

response = sunra_client.subscribe(
  "black-forest-labs/flux-kontext-pro/text-to-image",
  arguments={
    "prompt": "a cute cat, realistic, orange"
  }
)
print(response["images"][0]["url"])

streaming responses

import sunra_client

application = "black-forest-labs/flux-kontext-pro/text-to-image"
arguments={"prompt": "a cute cat, realistic, orange"}

for event in sunra_client.stream(application, arguments):
    print(f"Received event: {event}")

Asynchronous requests

The client also supports asynchronous requests out of the box. Here's an example:

import asyncio
import sunra_client

async def main():
    response = await sunra_client.subscribe_async("black-forest-labs/flux-kontext-pro/text-to-image", arguments={"prompt": "a cute cat, realistic, orange"})
    print(response["images"][0]["url"])


asyncio.run(main())

Queuing requests

When you want to send a request and keep receiving updates on its status, you can use the submit method. Here's an example:

import asyncio
import sunra_client

async def main():
    response = await sunra_client.submit_async("black-forest-labs/flux-kontext-pro/text-to-image", arguments={"prompt": "a cute cat, realistic, orange"})

    logs_index = 0
    async for event in response.iter_events():
        if isinstance(event, sunra_client.Queued):
            print("Queued. Position:", event.position)
        elif isinstance(event, (sunra_client.InProgress, sunra_client.Completed)):
            print(event)

    result = await response.get()
    print(result["images"][0]["url"])


asyncio.run(main())

Credits

This project is derived from

and adapted to work with sunra.ai. The original project is licensed under the MIT/Apache2.0 License. We extend our gratitude to the original authors for their contributions.

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

sunra_client-0.1.3.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sunra_client-0.1.3-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file sunra_client-0.1.3.tar.gz.

File metadata

  • Download URL: sunra_client-0.1.3.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for sunra_client-0.1.3.tar.gz
Algorithm Hash digest
SHA256 be108c98cd26f0d495fb38fc2bc984e0c4d420c74a8c90dca59aa0f42db35e73
MD5 e2d609ae134683a688e45dd1038b6b65
BLAKE2b-256 0602dfbf17a8d752b5bc69a0b7962b270454cbc53fbff6728de6cb78bb2e3b27

See more details on using hashes here.

File details

Details for the file sunra_client-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: sunra_client-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.2

File hashes

Hashes for sunra_client-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 1bb4471271ef1022d65170c9f6a03fb4f9b6f275c01887be2fcc8fa7733e5962
MD5 667c4b290c50a92ea6ffaf1018de431a
BLAKE2b-256 1b3bb6c55fda09afed975bb21d55d4b861cf24248ffd574d123c7ebc94b3f418

See more details on using hashes here.

Supported by

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