Skip to main content

Python SDK for the Diffio API.

Project description

Diffio Python SDK

The Diffio Python SDK helps you call the Diffio API from Python. This version covers project creation, upload, generation, progress checks, and download URLs. Requires Python 3.8 or later.

Install

pip install diffio

For local development:

cd diffio-python
pip install -e .

Configuration

Set the API key with DIFFIO_API_KEY. If you need to set the base URL explicitly, use the production endpoint with DIFFIO_API_BASE_URL.

export DIFFIO_API_KEY="diffio_live_..."
export DIFFIO_API_BASE_URL="https://api.diffio.ai/v1"

Request options

Use request options to override headers, timeouts, retries, or the API key per request. You can also pass timeoutInSeconds as an alias for timeout.

from diffio import DiffioClient, RequestOptions

client = DiffioClient(apiKey="diffio_live_...")
projects = client.list_projects(
    requestOptions=RequestOptions(
        headers={"X-Debug": "1"},
        timeout=30.0,
        maxRetries=2,
        retryBackoff=0.5,
    )
)

Create a project and generation

create_project uploads the file and returns the project metadata.

from diffio import DiffioClient

client = DiffioClient(apiKey="diffio_live_...")
file_path = "sample.wav"
project = client.create_project(
    filePath=file_path,
)

generation = client.create_generation(
    apiProjectId=project.apiProjectId,
    model="diffio-2",
    sampling={"steps": 12, "guidance": 1.5},
)

print(generation.generationId)

Audio isolation helper

from diffio import DiffioClient

client = DiffioClient(apiKey="diffio_live_...")
result = client.audio_isolation.isolate(
    filePath="sample.wav",
    model="diffio-2",
    sampling={"steps": 12, "guidance": 1.5},
)

print(result.generation.generationId)

Restore audio in one call

This helper runs the full flow and returns the downloaded bytes plus a metadata dict.

from diffio import DiffioClient

client = DiffioClient(apiKey="diffio_live_...")
audio_bytes, info = client.restore_audio(
    filePath="sample.wav",
    model="diffio-2",
    sampling={"steps": 12, "guidance": 1.5},
    onProgress=lambda progress: print(progress.status),
)

if info["error"]:
    print(info["error"])
else:
    with open("restored.mp3", "wb") as handle:
        handle.write(audio_bytes)

print(info["apiProjectId"], info["generationId"])

Generation progress

from diffio import DiffioClient

client = DiffioClient(apiKey="diffio_live_...")
progress = client.generations.get_progress(
    generationId="gen_123",
    apiProjectId="proj_123",
)

print(progress.status)

Generation download

from diffio import DiffioClient

client = DiffioClient(apiKey="diffio_live_...")
download = client.generations.download(
    generationId="gen_123",
    apiProjectId="proj_123",
    downloadType="mp3",
    downloadFilePath="restored.mp3",
)

print(download.downloadUrl)

If you only need the URL, use client.generations.get_download.

List projects

from diffio import DiffioClient

client = DiffioClient(apiKey="diffio_live_...")
projects = client.projects.list()

for project in projects.projects:
    print(project.apiProjectId, project.status)

List project generations

from diffio import DiffioClient

client = DiffioClient(apiKey="diffio_live_...")
generations = client.projects.list_generations(apiProjectId="proj_123")

for generation in generations.generations:
    print(generation.generationId, generation.status)

Send a test webhook event

from diffio import DiffioClient

client = DiffioClient(apiKey="diffio_live_...")
event = client.webhooks.send_test_event(
    eventType="generation.completed",
    mode="live",
    samplePayload={"apiProjectId": "proj_123"},
)

print(event.svixMessageId)

Verify webhook signatures

Use the raw request body (bytes) plus the svix-* headers and your webhook signing secret.

from fastapi import FastAPI, Request, HTTPException
from diffio import DiffioClient
import os

app = FastAPI()
client = DiffioClient(apiKey=os.environ["DIFFIO_API_KEY"])

@app.post("/webhooks/diffio")
async def diffio_webhook(request: Request):
    payload = await request.body()
    headers = request.headers
    try:
        event = client.webhooks.verify_signature(
            payload=payload,
            headers=headers,
            secret=os.environ["DIFFIO_WEBHOOK_SECRET"],
        )
    except Exception:
        raise HTTPException(status_code=400, detail="Invalid signature")
    print("Webhook received", event.eventType)
    return {"ok": True}

Tutorials

  • Audio restoration CLI tutorial: tutorials/audio-restoration-cli/README.md

Runtime compatibility

Use Python 3.8 or later.

Tests

cd diffio-python
python -m pip install -r requirements-dev.txt
python -m pytest

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

diffio-0.1.3.tar.gz (22.5 kB view details)

Uploaded Source

Built Distribution

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

diffio-0.1.3-py3-none-any.whl (17.2 kB view details)

Uploaded Python 3

File details

Details for the file diffio-0.1.3.tar.gz.

File metadata

  • Download URL: diffio-0.1.3.tar.gz
  • Upload date:
  • Size: 22.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for diffio-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d72de033f1ec1e55daafd197a7dba6d95fee20685c6e266924086138175728c4
MD5 6b1a8961776a4152a677574393583c3b
BLAKE2b-256 4d15050b1e2c307d8e5818390dcee326f2d1441fe2ba69fe4d628b554e6ce36f

See more details on using hashes here.

Provenance

The following attestation bundles were made for diffio-0.1.3.tar.gz:

Publisher: publish-python.yml on Diffio-AI/diffio-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file diffio-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: diffio-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 17.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for diffio-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 33bd917b974edfbb261f27ad1c1a892c07fa820bb5c425fff35d3293f915e4b8
MD5 b5bd1bf6be2519152dcedae6eeac6a16
BLAKE2b-256 62c897999e865f6b8eacc413a97476ad7c5b758c90a638570fdb80aa42a45221

See more details on using hashes here.

Provenance

The following attestation bundles were made for diffio-0.1.3-py3-none-any.whl:

Publisher: publish-python.yml on Diffio-AI/diffio-python

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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