Introduction

The client library for Python offers an easy-to-use interface to interact with Sunra’s services.

Installation

To integrate the client into your project, install it using pip:

pip install sunra-client

Features

Calling Endpoints

Sunra manages endpoint requests through a queue system, ensuring reliability and scalability. Use the subscribe method to submit a request and await the result.

Example:

import sunra_client

def on_queue_update(update):
    if isinstance(update, sunra_client.InProgress):
        for log in update.logs:
           print(log["message"])

result = sunra_client.subscribe(
    "black-forest-labs/flux-kontext-pro/text-to-image",
    arguments={
    	prompt: 'A Studio Ghibli-inspired seaside town with colorful houses, laundry flapping, and cats sleeping on windowsills.',
    	width: 1024,
    	height: 768,
    	output_format: 'jpeg'
    },
    with_logs=True,
    on_queue_update=on_queue_update,
)
print(result)

Queue Management

Manage your requests with these methods:

Submitting a Request

Submit a request and retrieve the request_id for later use.

Example:

import sunra_client

handler = sunra_client.submit(
    "black-forest-labs/flux-kontext-pro/text-to-image",
    arguments={
      prompt: 'A Studio Ghibli-inspired seaside town with colorful houses, laundry flapping, and cats sleeping on windowsills.',
      width: 1024,
      height: 768,
      output_format: 'jpeg'
    },
    webhook_url="https://optional.webhook.url/for/results",
)
request_id = handler.request_id
Checking Request Status

Retrieve the status of a request.

Example:

import sunra_client
status = sunra_client.status(request_id, with_logs=True)
Retrieving Request Results

Fetch the result of a completed request.

Example:

import sunra_client
result = sunra_client.result(request_id)

File Uploads

Upload files to obtain URLs for use in asynchronous requests.

Example:

import sunra_client

url = sunra_client.upload_file("path/to/file")

Support

Join our community for help or discussions:

We’re here to assist you!