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
image = client.generate_text_to_image(
model="p-image",
prompt="A beautiful sunset over a calm ocean",
sync=True
)
if isinstance(image, Image.Image):
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
client = PrunaClient()
image = client.generate_text_to_image(
model="p-image",
prompt="A serene mountain landscape",
sync=True
)
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)
Image Editing
from pruna_client import PrunaClient
from PIL import Image
client = PrunaClient()
# Edit an image
edited = client.generate_image_edit(
model="p-image-edit",
prompt="Make the image blue",
images=["path/to/image.png" | Image.Image | data URI],
sync=True
)
Running Tests
cd pruna_client
uv run pytest tests/ -v
Tests require PRUNA_API_KEY environment variable to be set.
Project details
Release history Release notifications | RSS feed
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.1.tar.gz
(26.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pruna_client-0.0.1.tar.gz.
File metadata
- Download URL: pruna_client-0.0.1.tar.gz
- Upload date:
- Size: 26.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57b4cb2330be45e19076332ba571365ae01d700014461c873c2d5e5a3782b252
|
|
| MD5 |
c2995800913de03cd561e8e991eb01c3
|
|
| BLAKE2b-256 |
17e1cd385c94e2448e00218f5560ec25e3fc8f391d2e7e07e4f87476467604dd
|
File details
Details for the file pruna_client-0.0.1-py3-none-any.whl.
File metadata
- Download URL: pruna_client-0.0.1-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d0b86b35722d3df58906a16bdabf0ff65200969c193a4206c64e640cb9c57522
|
|
| MD5 |
8e9c2cba8df00c2b9aa84affe94d928a
|
|
| BLAKE2b-256 |
d865d628c4f4bfd37d02ed5b677c11cf9c4f2504eeb64ccaec05e3a71ff644ec
|