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.4.tar.gz (23.5 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.4-py3-none-any.whl (7.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pruna_client-0.0.4.tar.gz
Algorithm Hash digest
SHA256 2d4a7e0f0624fc3061454bbc139715e4c3c5d0aeb851d7b30df751b0951f7334
MD5 40a8a61e3f523aaa3b9ef47d6a200f8c
BLAKE2b-256 6db036a4b4358f56f83da6009a74da77d2e507920b7a909e95ae40b5d50376fe

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pruna_client-0.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b3fadc133b2cb903ef1b014e604ba886be604d8049205e9eac1d0946a038cb7b
MD5 ee6026bd3e735a7593611a9a18b291d1
BLAKE2b-256 f8dbf1058265886da13e419f47ac6b517c8829ce17f7afd1b866b5a4c96084b5

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