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

Uploaded Python 3

File details

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

File metadata

  • Download URL: audd-1.4.3.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.3.tar.gz
Algorithm Hash digest
SHA256 cfad5a1a6770fe163ae771b506c3d418413e20371b2f3a108bfed59d5e4d6e7b
MD5 7fb12bb6f1ed0715c60cb6c74df24a97
BLAKE2b-256 c67a8731428d5376c18991c67ae5465cb8d7caf2d5e04a8726c10fb499d40dd9

See more details on using hashes here.

Provenance

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

File metadata

  • Download URL: audd-1.4.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 5d6dc11d9db671d711dfbb1ad7fe7ece1f614343ac0b72de07ce54cc2276a0a8
MD5 d991ceae7a5cabae32abc6430345fe58
BLAKE2b-256 9cff036d10762e1d71e8c38328aceb8d045f65e430566dbb9230ac6665bb9100

See more details on using hashes here.

Provenance

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