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.4.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.4-py3-none-any.whl (28.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: audd-1.4.4.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.4.tar.gz
Algorithm Hash digest
SHA256 df9fc4b4cecf084f7cac0132d6b619add6f18e9e7fe9e2af92b7be332108ac07
MD5 b7cd5984c6ff7a63caf6a3ceb85f5d56
BLAKE2b-256 6224c422d53bfb2c7de0f9ee467663a24bee49068b2b1041cbd94ba6cbbcaf15

See more details on using hashes here.

Provenance

The following attestation bundles were made for audd-1.4.4.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.4-py3-none-any.whl.

File metadata

  • Download URL: audd-1.4.4-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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 369a6af01ec7a36984b6bda7997333467b081fe4b8acda6ea2dbcb1bff4168a7
MD5 ccba4509347ccb8f757d0acf1f2666d5
BLAKE2b-256 199ad7f0d27bd3e54548e1afa20f462b417e56eca8d246b7e1f66394cf6dfaba

See more details on using hashes here.

Provenance

The following attestation bundles were made for audd-1.4.4-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