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

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pruna_client-0.0.3.tar.gz
Algorithm Hash digest
SHA256 19af3371591edd92c9296f5a6325a15e8aec8d33ada036e1ce2324142d79a9cb
MD5 252c24fdbeff89775f0f6c545618cd19
BLAKE2b-256 70899f5f3c5d19eae58663cf4fab420213d0519ec8c5af97847e0feb9fcfa06c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pruna_client-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5bf27dd806e711aa700ef113afbee02aebe9822db191b9938005c98010bb90c4
MD5 596e20327604b317a24a4b8c3c39a8a3
BLAKE2b-256 06fd9b54185a9f9b289eab8d44e7af6ee4611b76e90c60b5b16f105f5fd644c2

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