Skip to main content

No project description provided

Project description

Hedra Python Library

fern shield pypi

The Hedra Python library provides convenient access to the Hedra API from Python.

Installation

pip install hedra

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.portait.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:

  • 408 (Timeout)
  • 429 (Too Many Requests)
  • 5XX (Internal Server Errors)

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

hedra_python-0.1.0.tar.gz (23.1 kB view details)

Uploaded Source

Built Distribution

hedra_python-0.1.0-py3-none-any.whl (36.8 kB view details)

Uploaded Python 3

File details

Details for the file hedra_python-0.1.0.tar.gz.

File metadata

  • Download URL: hedra_python-0.1.0.tar.gz
  • Upload date:
  • Size: 23.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for hedra_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 78f87b241eff006dd1f3968f0163e0f3b03699229cdce9d868f18e3464c7f16b
MD5 4fcd9cd2cbc81ca8aecbf8ba1296fa5c
BLAKE2b-256 30700b63fb8f85add5fd5ede6f35a3dac51cf1415e10fe1b5d9b37f3ff96f706

See more details on using hashes here.

File details

Details for the file hedra_python-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: hedra_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.14

File hashes

Hashes for hedra_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 243aea29fbbb11886e45a5499107bacf292c166239692b3ddab09a8f887cd595
MD5 d26e937a64c5a9c8f13aa3c88204c850
BLAKE2b-256 719b437c314b092cdd8d036518278465924eced1fec1ad9417fb0d707775a65d

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page