No project description provided
Project description
Hedra Python Library
The Hedra Python library provides convenient access to the Hedra API from Python.
Installation
pip install hedra-python
Reference
A full reference for this library is available here.
Usage
Instantiate and use the client with the following:
from hedra import Hedra
client = Hedra(
api_key="YOUR_API_KEY",
)
audio_url = None
with open("audio.mp3", "rb") as f:
response = client.audio.upload_audio(file=f)
audio_url = response.url
image_url = None
with open("image.jpg", "rb") as f:
response = client.portrait.upload_image(file=f)
image_url = response.url
# with open("example.mp3", "rb") as f:
response = client.characters.initialize_talking_head_avatar(
voice_url=audio_url,
avatar_image=image_url
)
print(response)
client.audio.upload_audio()
Async Client
The SDK also exports an async
client so that you can make non-blocking calls to our API.
import asyncio
from hedra import AsyncHedra
client = AsyncHedra(
api_key="YOUR_API_KEY",
)
async def main() -> None:
await client.audio.upload_audio()
asyncio.run(main())
Exception Handling
When the API returns a non-success status code (4xx or 5xx response), a subclass of the following error will be thrown.
from hedra.core.api_error import ApiError
try:
client.audio.upload_audio(...)
except ApiError as e:
print(e.status_code)
print(e.body)
Advanced
Retries
The SDK is instrumented with automatic retries with exponential backoff. A request will be retried as long as the request is deemed retriable and the number of retry attempts has not grown larger than the configured retry limit (default: 2).
A request is deemed retriable when any of the following HTTP status codes is returned:
Use the max_retries
request option to configure this behavior.
client.audio.upload_audio(..., request_options={
"max_retries": 1
})
Timeouts
The SDK defaults to a 60 second timeout. You can configure this with a timeout option at the client or request level.
from hedra import Hedra
client = Hedra(
...,
timeout=20.0,
)
# Override timeout for a specific method
client.audio.upload_audio(..., request_options={
"timeout_in_seconds": 1
})
Custom Client
You can override the httpx
client to customize it for your use-case. Some common use-cases include support for proxies
and transports.
import httpx
from hedra import Hedra
client = Hedra(
...,
httpx_client=httpx.Client(
proxies="http://my.test.proxy.example.com",
transport=httpx.HTTPTransport(local_address="0.0.0.0"),
),
)
Contributing
While we value open-source contributions to this SDK, this library is generated programmatically. Additions made directly to this library would have to be moved over to our generation code, otherwise they would be overwritten upon the next generated release. Feel free to open a PR as a proof of concept, but know that we will not be able to merge it as-is. We suggest opening an issue first to discuss with us!
On the other hand, contributions to the README are always very welcome!
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
File details
Details for the file hedra_python-0.1.1.tar.gz
.
File metadata
- Download URL: hedra_python-0.1.1.tar.gz
- Upload date:
- Size: 23.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d84bede2fb7869e45abbf5bb54d0a117cf227ddeea14f88201a81e1f41f9e316 |
|
MD5 | 5667f24fdb9e6184c7b7d0f6f7506d18 |
|
BLAKE2b-256 | 348e0b207c9e6f1f25f046e321575e3f133a33cd7a1214cd68d5b115b4d2d6bc |
File details
Details for the file hedra_python-0.1.1-py3-none-any.whl
.
File metadata
- Download URL: hedra_python-0.1.1-py3-none-any.whl
- Upload date:
- Size: 36.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.13.0 Darwin/24.0.0
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 59cdfb9bb139ebaedca9429bb276c58135e44caba2b373226352d661b98f994a |
|
MD5 | 757801fdf2ec284dbc478638ade99990 |
|
BLAKE2b-256 | 449295f654f848b8d43484b0ff382fff7a4785947cfe5a26d3e637a5635e5a44 |