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.2.tar.gz (26.6 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.2-py3-none-any.whl (6.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pruna_client-0.0.2.tar.gz
Algorithm Hash digest
SHA256 f6001e4a2d3855d32aac4975b62d37b2059ea670d4780ab2f36ca221b3d388c4
MD5 e7b9ccded38a2548599ab6a03c877af5
BLAKE2b-256 3dbc908e918fe5ed6dee431e420fbcdfc69e3aedb100a7e9af08f2ee7469f478

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for pruna_client-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 03cde6dd98a9c4a0c3a72bf44289ddbd217ee28df3fad23cefb1ba7039b21bca
MD5 fe8abb34fc1ed8c1c97ec6392f66c340
BLAKE2b-256 cf0774020434b483fa2b2b732c6746309dbc3ce91c9dff8efc303d80ef57c996

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