Skip to main content

Official Pruna API client for synchronous and asynchronous image generation and editing

Project description

Pruna Client

Official Pruna API client for synchronous and asynchronous image generation and editing.

Installation

uv add pruna-client

Or install from source:

cd pruna_client
uv pip install -e .

Quick Start

from pruna_client import PrunaClient

# Initialize client
client = PrunaClient(api_key="your_api_key")
# Or set PRUNA_API_KEY environment variable

# Generate image synchronously
response = client.generate_text_to_image(
    model="p-image",
    prompt="A beautiful sunset over a calm ocean",
    sync=True
)

if isinstance(response.image, Image.Image):
    response.image.save("output.png")

Features

  • Synchronous Image Generation: Generate images and wait for completion
  • Asynchronous Image Generation: Start generation and poll for status
  • Image Editing: Edit images using prompts
  • File Upload: Upload images from file paths, PIL Images, or data URIs
  • Status Polling: Poll async operations until completion

Usage Examples

Synchronous Generation

from pruna_client import PrunaClient
from PIL import Image

client = PrunaClient()
response = client.generate_text_to_image(
    model="p-image",
    prompt="A serene mountain landscape",
    sync=True
)

if isinstance(response.image, Image.Image):
    response.image.save("output.png")

Asynchronous Generation

from pruna_client import PrunaClient

client = PrunaClient()

# Start async generation
response = client.generate_text_to_image(
    model="p-image",
    prompt="An abstract painting",
    sync=False
)

# Poll for completion
final_response = client.poll_status(
    response=response,
    poll_interval=2.0,
    max_wait=120
)

if final_response.status == "succeeded":
    image = client._download_image(final_response.generation_url)
    if isinstance(image, Image.Image):
        image.save("output.png")

Image Editing

from pruna_client import PrunaClient
from PIL import Image

client = PrunaClient()

# Edit an image
response = client.generate_image_edit(
    model="p-image-edit",
    prompt="Make the image blue",
    images=["path/to/image.png" | Image.Image | data URI],
    sync=True
)

if isinstance(response.image, Image.Image):
    response.image.save("output.png")

Running Tests

cd pruna_client
uv run pytest tests/ -v

Tests require PRUNA_API_KEY environment variable to be set.

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

pruna_client-0.0.5.tar.gz (25.0 kB view details)

Uploaded Source

Built Distribution

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

pruna_client-0.0.5-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file pruna_client-0.0.5.tar.gz.

File metadata

  • Download URL: pruna_client-0.0.5.tar.gz
  • Upload date:
  • Size: 25.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.18

File hashes

Hashes for pruna_client-0.0.5.tar.gz
Algorithm Hash digest
SHA256 7e476d06fed3fc75d44e9a3eb5f75c6d70923c9edc97dc3fd55a8912a6206097
MD5 cad79007fc3625538605b9fce0eb41b2
BLAKE2b-256 b5730c9e2417daf3dd104fa995e2c579f09c6979450458d031ccdd0f6077db3a

See more details on using hashes here.

File details

Details for the file pruna_client-0.0.5-py3-none-any.whl.

File metadata

File hashes

Hashes for pruna_client-0.0.5-py3-none-any.whl
Algorithm Hash digest
SHA256 b16cbed663a3a882b8c343bd06d91f84a04547380646c01e658d548bab0d5e29
MD5 9410736b5bf0e9ff5ff0a41079dc117d
BLAKE2b-256 0fc04f28e22493ea1438eda98b6bbd20442917a2dbae5886b421c57ef8c7cfb4

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