Skip to main content

Official Python SDK for the Hadidy Audio Transcoding API

Project description

hadidy-audio

Official Python SDK for the Hadidy Audio Transcoding API. Supports Python 3.10+ with both synchronous and asynchronous clients. Zero required dependencies beyond httpx and pydantic.

Installation

pip install hadidy-audio

Python 3.10+ required. The async client uses asyncio — no extra install needed.


Quick Start — Synchronous

from hadidy import AudioClient

client = AudioClient(api_key="had_live_...")

with open("podcast.wav", "rb") as f:
    job = client.jobs.create(f, output_format="mp3", bitrate="192k")

completed = client.jobs.wait_for_completion(job["id"], timeout=300)
print(completed["output_url"])

Quick Start — Async

import asyncio
from hadidy import AsyncAudioClient

async def main():
    async with AsyncAudioClient(api_key="had_live_...") as client:
        async for job in client.jobs.list_all(status="completed"):
            print(f"{job['file_name']}{job['output_url']}")

asyncio.run(main())

Live Streaming

WHIP (OBS 30+ / Larix — recommended)

from hadidy import AudioClient

client = AudioClient(api_key="had_live_...")

# Create a session — WHIP is the default protocol
session = client.live.create_session(
    title="Friday Night Show",
    ingest_protocol="whip",   # default; can be omitted
    recording_enabled=True,
)
client.live.start_session(session["id"])

print("WHIP endpoint:", session["ingest_url"])
# → https://ingest.hadidy.com/{stream_key}/whip

# OBS 30+: Settings → Stream → Service: WHIP
#   Server: paste session["ingest_url"]  (no separate stream key field)

RTMPS (OBS older / vMix / Streamlabs)

session = client.live.create_session(
    title="Friday Night Show",
    ingest_protocol="rtmp",   # externally TLS-encrypted RTMPS on port 4936
    recording_enabled=True,
)
client.live.start_session(session["id"])

print("RTMPS server:", session["ingest_url"])  # rtmps://rtmps.hadidy.com:4936/
print("Stream key:  ", session["stream_key"])

# OBS: Settings → Stream → Service: Custom RTMPS
#   Server:     paste session["ingest_url"]
#   Stream Key: paste session["stream_key"]

Push track metadata mid-stream

# Call on every track change in your DJ software
client.live.update_now_playing(
    session["id"],
    title="Midnight City",
    artist="M83",
    album="Hurry Up, We're Dreaming",
    cover_url="https://example.com/artwork.jpg",
    # Pre-load the upcoming track on listeners' devices:
    next_title="Resonance",
    next_artist="Home",
    next_cover_url="https://example.com/next-artwork.jpg",
)

# Clear track info between sets
client.live.clear_now_playing(session["id"])

Stop and retrieve recordings

client.live.stop_session(session["id"])

recordings = client.live.list_recordings(session["id"])
for r in recordings:
    print(r["download_url"], r["duration_seconds"])

Async live session

import asyncio
from hadidy import AsyncAudioClient

async def broadcast():
    async with AsyncAudioClient(api_key="had_live_...") as client:
        session = await client.live.create_session(title="Night Show", ingest_protocol="whip")
        await client.live.start_session(session["id"])
        print("Streaming at:", session["ingest_url"])

        # Later, on track change:
        await client.live.update_now_playing(session["id"], title="Atlas", artist="Battles")

        # Stop when done
        await client.live.stop_session(session["id"])

asyncio.run(broadcast())

Webhook Verification — FastAPI

from hadidy import WebhookVerifier
from fastapi import FastAPI, Request, HTTPException, Depends
import os

app = FastAPI()
verifier = WebhookVerifier(secret=os.environ["HADIDY_WEBHOOK_SECRET"])

@app.post("/hooks/hadidy")
async def webhook(request: Request, _=Depends(verifier.fastapi_dependency())):
    event = await request.json()
    print(event["type"], event["data"])
    return {"ok": True}

API Coverage

Resource Methods
client.jobs list(), list_all(), get(), create(), delete(), get_output(), wait_for_completion()
client.presets list(), list_all(), get(), create(), update(), delete()
client.codecs list_codecs(), list_formats(), capabilities()
client.analysis analyze(file)
client.audio waveform_data(), silence(), get_metadata(), update_metadata(), concat()
client.webhooks list(), get(), create(), update(), delete(), deliveries(), test()
client.billing balance(), history(), service_costs()
client.folders list(), get(), breadcrumb(), create(), update(), delete(), move_files()
client.sharing list(), get(), create(), update(), delete(), get_public_info(), verify_passcode()
client.live create_session(), get_session(), list_sessions(), list_sessions_all(), update_session(), start_session(), stop_session(), restart_session(), delete_session(), regenerate_key(), update_now_playing(), clear_now_playing(), list_sources(), add_source(), list_participants(), list_recordings()

All methods have async equivalents on AsyncAudioClient.


Error Handling

from hadidy import AudioClient, RateLimitError, NotFoundError, ValidationError, HadidyError

client = AudioClient(api_key="had_live_...")

try:
    job = client.jobs.get("nonexistent-id")
except NotFoundError:
    print("Job not found")
except RateLimitError as e:
    print(f"Rate limited — retry after {e.retry_after}s")
except ValidationError as e:
    print(f"Bad request: {e}")
except HadidyError as e:
    print(f"API error {e.status}: {e}")

Configuration

client = AudioClient(
    api_key="had_live_...",              # required
    base_url="https://api.hadidy.com",   # default
    timeout=30.0,                         # seconds — default: 30.0
    max_retries=2,                        # default: 2
)

License

MIT

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

hadidy_audio-0.1.2.tar.gz (10.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

hadidy_audio-0.1.2-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file hadidy_audio-0.1.2.tar.gz.

File metadata

  • Download URL: hadidy_audio-0.1.2.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for hadidy_audio-0.1.2.tar.gz
Algorithm Hash digest
SHA256 40a1f1b677808f3980f8aed80e36e1c576cce44ddb0a07510b1792eda2f2542b
MD5 808657b08cfe86a6ee71951df689847b
BLAKE2b-256 feb8edc4e36632f53d5e074f8a122195d6cf1f4a6e3303a9d4f7fcce4d048b8e

See more details on using hashes here.

File details

Details for the file hadidy_audio-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: hadidy_audio-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 16.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.8

File hashes

Hashes for hadidy_audio-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a12ce2249906dcbc7a234d433e7fcd6318028a727b347dbe1fbd934d8773051a
MD5 2c1a3737cf8394f7e67b0ba6e4fe6fbf
BLAKE2b-256 7280701aee7a5ea9175fdf604c4c5be3bc27a85c49694543ef3edc9095afc2e2

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