Skip to main content

A modular, async Python client for the Shazam API

Project description

xazam

A modular, async Python client for the Shazam API, built on top of shazamio_core for robust audio fingerprinting.

Features

  • Track identification — send audio bytes and get back track metadata.
  • Artist metadata scraping — resolve artist pages and query the Apple Music catalog proxy.
  • Modular transportShazamTransport handles headers and sessions; ShazamClient and ShazamScraper build on top of it.

Install

pip install -e .
# or with dev dependencies
pip install -e ".[dev]"

Quick start

Identify a track (typed API — recommended)

import asyncio
from xazam import ShazamClient, ShazamTransport

async def main():
    with open("song.mp3", "rb") as f:
        audio = f.read()

    async with ShazamTransport() as transport:
        client = ShazamClient(transport)
        result = await client.identify(audio)

    if result.matched:
        track = result.track
        print(f"{track.title}{track.subtitle}")
        print(f"Cover art: {track.cover_art}")
        print(f"Apple Music: {track.apple_music_url}")
        print(f"Spotify: {track.spotify_uri}")
        print(f"Lyrics: {track.lyrics[:200]}...")
    else:
        print("No match")

asyncio.run(main())

Fetch extra track metadata

After identification, query the track detail endpoint for lyrics, related videos, and extended metadata:

    extra = await client.get_track_info(track.key)
    print(extra.metadata_table)   # {'Album': '…', 'Released': '…', 'Label': '…'}
    print(extra.related_videos)    # ['https://youtube.com/watch?v=…', ...]

Identify a track (legacy raw-dict API)

identify_track() still returns the raw Shazam JSON for backwards compatibility:

    result = await client.identify_track(audio)
    print(result["track"]["title"], "—", result["track"]["subtitle"])

Scrape artist metadata

import asyncio
from xazam import ShazamScraper, ShazamTransport

async def main():
    async with ShazamTransport() as transport:
        scraper = ShazamScraper(transport)
        data = await scraper.get_artist_metadata("3996865")

    artist = data["results"]["artists"]["data"][0]
    print(artist["attributes"]["name"])

asyncio.run(main())

CLI

# Identify a file
python -m xazam_cli identify --file song.mp3

# Scrape artist metadata
python -m xazam_cli scrape --artist-id 3996865

Tests

Live integration tests hit the real Shazam API. Set a custom audio file via the environment:

export SHAZAMPY_TEST_AUDIO="/path/to/track.mp3"
pytest tests/test_integration.py -v

Architecture

Module Purpose
client.py ShazamClient — high-level track identification
scraper.py ShazamScraper — artist name resolution + catalog search
transport.py ShazamTransport — aiohttp sessions, headers, request helpers
models.py Track, Artist dataclasses

Status

  • ✅ Artist metadata scraping (405 resolved via dedicated web-page session)
  • ✅ Track identification (matches returned correctly via shazamio_core fingerprinting)

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

xazam-0.1.2a3.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

xazam-0.1.2a3-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file xazam-0.1.2a3.tar.gz.

File metadata

  • Download URL: xazam-0.1.2a3.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xazam-0.1.2a3.tar.gz
Algorithm Hash digest
SHA256 990cbdba7fcae7017c9560f803c1273bcc9006884b4620b56e277556a0a79494
MD5 88f3f5b850cd8715b65df5f3ab152d21
BLAKE2b-256 2ef675fec005179d945a225a39601f1c2a429b1b7e9d67d1955f93d0b23ec144

See more details on using hashes here.

File details

Details for the file xazam-0.1.2a3-py3-none-any.whl.

File metadata

  • Download URL: xazam-0.1.2a3-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for xazam-0.1.2a3-py3-none-any.whl
Algorithm Hash digest
SHA256 f6bfb9ba6bb5fb12fd31df36e426dc15357dcf887f5335ffa9a5b7884692d454
MD5 0bda8e2c0e9fc49820bfd691b77ab914
BLAKE2b-256 87789c9d728be98915998f9e1fe8d25dec1d0856eac7095bad1d6a9108f51a75

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