Skip to main content

Official Python SDK for the AudD music recognition API.

Project description

audd

CI Contract PyPI Python versions

Official Python SDK for the AudD music recognition API.

Quickstart

pip install audd
from audd import AudD

audd = AudD(api_token="test")  # use your token from https://dashboard.audd.io
result = audd.recognize("https://audd.tech/example.mp3")
if result:
    print(f"{result.artist}{result.title}")

Capabilities

What How
Recognize a short clip (≤25s) audd.recognize(source)
Recognize a long file (hours, days) audd.recognize_enterprise(source, limit=...)
Manage stream recognition (set callback, longpoll for events) audd.streams.*

source accepts a URL, a file path, a file-like object, or raw bytes — auto-detected.

Async

Use AsyncAudD instead — same surface:

from audd import AsyncAudD

async def main():
    audd = AsyncAudD(api_token="test")
    try:
        result = await audd.recognize("https://audd.tech/example.mp3")
        print(result)
    finally:
        await audd.aclose()

Errors

Every server error becomes a typed exception:

from audd import AudD, AudDAuthenticationError, AudDSubscriptionError

try:
    AudD(api_token="bad").recognize("https://x.mp3")
except AudDAuthenticationError as e:
    print(f"check your token: {e.error_code} {e.message}")
except AudDSubscriptionError:
    print("this endpoint isn't enabled on your token")

The full hierarchy is documented in src/audd/errors.py. Every AudDAPIError carries error_code, message, http_status, request_id, requested_params, request_method, branded_message, and raw_response.

Forward compatibility

Models accept and round-trip unknown server fields via model_extra:

result = audd.recognize("https://example.mp3", return_=["apple_music"])
print(result.apple_music.url)               # typed
print(result.model_extra)                   # any other unknown fields

If AudD adds a new metadata block tomorrow (e.g., tidal), you can read it as result.model_extra["tidal"] today — no SDK release needed. The next SDK release adds the typed tidal field, and both paths keep working.

Streams

Manage real-time stream recognition (set callback, longpoll for events):

audd.streams.set_callback_url("https://your.server/cb")
audd.streams.add("https://your.stream.url", radio_id=42)
for event in audd.streams.list():
    print(event)

Receiving events without exposing your token

For browser widgets and other contexts where shipping the api_token would leak it, derive a category server-side and share that with the consumer:

from audd import LongpollConsumer

# `category` is derived server-side via AudD(...).streams.derive_longpoll_category(radio_id),
# then shared with the browser/widget. The consumer carries no api_token.
consumer = LongpollConsumer(category="abc123def")
for event in consumer.iterate(timeout=30):
    print(event)

Configuration

import httpx
from audd import AudD

audd = AudD(
    api_token="...",
    max_retries=3,           # retry budget per call
    backoff_factor=0.5,      # initial backoff seconds (jittered)
    httpx_client=httpx.Client(proxies="http://corp-proxy:8080"),
)

Default timeouts: 30s connect / 60s read for standard endpoints, 30s connect / 1 hour read for the enterprise endpoint. Pass timeout= per call to override.

Concurrency: AudD and AsyncAudD are safe for concurrent use — share one instance across threads or asyncio tasks. set_api_token(...) rotates the token safely; in-flight requests continue with the old token, subsequent requests use the new one.

Custom catalog (advanced — not for music recognition)

The custom-catalog endpoint is NOT how you submit audio for music recognition. For recognition, use recognize() or recognize_enterprise(). The custom-catalog endpoint adds songs to your private fingerprint database for your account. Requires special access — contact api@audd.io if you need it.

audd.custom_catalog.add(audio_id=42, source="https://my.song.mp3")

Advanced

For endpoints not yet wrapped by typed methods on this SDK, use the raw-request escape hatch:

raw = audd.advanced.raw_request("someNewMethod", {"q": "x"})

Spec contract

This SDK builds against the audd-openapi spec. The contract tests in tests/contract/ validate the parser against the canonical fixture set on every push, on a daily cron, and on every spec update.

License

MIT — see LICENSE.

Support

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

audd-1.4.2.tar.gz (22.6 kB view details)

Uploaded Source

Built Distribution

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

audd-1.4.2-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

Details for the file audd-1.4.2.tar.gz.

File metadata

  • Download URL: audd-1.4.2.tar.gz
  • Upload date:
  • Size: 22.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for audd-1.4.2.tar.gz
Algorithm Hash digest
SHA256 79e066be0f19fd5d459d64c7230aa0879effb0a179625ceb2a1b7f761072ae94
MD5 fa27ec22057ef12b36679577e488856a
BLAKE2b-256 93069e08ad05b2ce9fead334ea5c2cac25845965bf236556e726aecb6e05953e

See more details on using hashes here.

Provenance

The following attestation bundles were made for audd-1.4.2.tar.gz:

Publisher: release.yml on AudDMusic/audd-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 audd-1.4.2-py3-none-any.whl.

File metadata

  • Download URL: audd-1.4.2-py3-none-any.whl
  • Upload date:
  • Size: 28.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for audd-1.4.2-py3-none-any.whl
Algorithm Hash digest
SHA256 8c78214e2adf003d1b92d7b814b3403d623784573222652f131753107a8612b3
MD5 94b9f0b3e614a0ff0e855826f99de78b
BLAKE2b-256 8330f99f1060b9d2c593361d72b48c08947f444d428224a3ed101f16cbbb996f

See more details on using hashes here.

Provenance

The following attestation bundles were made for audd-1.4.2-py3-none-any.whl:

Publisher: release.yml on AudDMusic/audd-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