Official Pruna API client for synchronous and asynchronous image generation and editing
Project description
Pruna Client
Official Pruna API client for image and video generation and editing.
Installation
uv add pruna-client
Quick Start
from pruna_client import PrunaClient
from PIL import Image
# Initialize client (uses PRUNA_API_KEY env var if api_key not provided)
client = PrunaClient(api_key="your_api_key")
# Generate image
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")
Basic Usage
General Generation
response = client.generate(
model="p-image",
input={"prompt": "A beautiful sunset over a calm ocean"},
sync=True
)
# or batch
responses = client.generate_batch(
requests=[
{"model": "p-image", "input": {"prompt": "A beautiful sunset over a calm ocean"}},
{"model": "p-image", "input": {"prompt": "A beautiful sunrise over a calm ocean"}},
],
sync=True
)
Text to Image
response = client.generate_text_to_image(
model="p-image",
prompt="A beautiful sunset over a calm ocean",
sync=True
)
Image Editing
response = client.generate_image_edit(
model="p-image-edit",
prompt="Edit the image to make it more beautiful",
images=["path/to/image.png"],
sync=True
)
Text to Video
response = client.generate_text_to_video(
model="p-video",
prompt="A beautiful sunset over a calm ocean",
sync=True
)
Async Usage
The client supports async operations for better performance when making multiple requests or integrating with async applications.
General Generation (Async)
import asyncio
from pruna_client import PrunaClient
from PIL import Image
async def main():
client = PrunaClient(api_key="your_api_key")
response = await client.agenerate(
model="p-image",
input={"prompt": "A beautiful sunset over a calm ocean"},
sync=True
)
if isinstance(response.image, Image.Image):
response.image.save("output.png")
await client.aclose()
asyncio.run(main())
# or batch
responses = await client.agenerate_batch(
requests=[
{"model": "p-image", "input": {"prompt": "A beautiful sunset over a calm ocean"}},
{"model": "p-image", "input": {"prompt": "A beautiful sunrise over a calm ocean"}},
],
sync=True
)
Running Tests
uv run pytest tests/integration/test_general.py -v
uv run pytest tests/integration/test_text_to_image.py -v
uv run pytest tests/integration/test_image_edit.py -v
uv run pytest tests/integration/test_text_to_video.py -v
uv run pytest tests/integration/test_video_edit.py -v
uv run pytest tests/integration/test_image_to_video.py -v
uv run pytest tests/integration/test_batch_generation.py -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
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.6.tar.gz.
File metadata
- Download URL: pruna_client-0.0.6.tar.gz
- Upload date:
- Size: 29.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4163e87b6072c522e9cd8c653735e792f1aee22af08f6eac5ebba709233c0658
|
|
| MD5 |
d21a02fc117a93e7f22ff420299f3383
|
|
| BLAKE2b-256 |
039c1bcd93037805056b1d05a69e9742fe12365c1c62b6113889a917711866e4
|
File details
Details for the file pruna_client-0.0.6-py3-none-any.whl.
File metadata
- Download URL: pruna_client-0.0.6-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.18
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb0577b5180cf7e90903e863032d20f407f826ee0637da871b59e6fa8a2f38c1
|
|
| MD5 |
12395bc39e4ca5295e07c5edce2ffda3
|
|
| BLAKE2b-256 |
6c54812fdebd487b97acd12588c5010cf604aa21605d2f9248ff0032dca22359
|