Skip to content

Add includes support to lookup_by_url - #6

Merged
zas merged 3 commits into
mainfrom
feature/lookup-by-url-includes
Sep 11, 2026
Merged

zas merged 3 commits into
mainfrom
feature/lookup-by-url-includes

Conversation

@zas

@zas zas commented Sep 11, 2026

Copy link
Copy Markdown
Owner

Summary

Adds an optional includes argument to lookup_by_url (both async MusicBrainzClient and SyncMusicBrainzClient), enabling relationship subqueries on the /url endpoint.

Motivation

lookup_by_url previously only returned the bare URL entity (its MBID and resource), with no way to discover which entities the URL is linked to. The MusicBrainz /url endpoint supports inc=<entity>-rels, which lets a URL be resolved back to its linked entities — e.g. finding an artist from their Spotify, Discogs, or social-media URL in a single request.

Changes

  • MusicBrainzClient.lookup_by_url(*urls, includes=None) — async, adds inc= param.
  • SyncMusicBrainzClient.lookup_by_url(*urls, includes=None) — sync, same.
  • Url model gains an optional relations: list[MBModel] | None field (consistent with the existing Work/Event models) for typed access.
  • Tests:
    • tests/test_client.py: single URL, multiple URLs, and includes resolving an artist relation.
    • tests/test_sync_client.py: includes path.
    • tests/test_models.py: Url deserialization with relations.
    • tests/conftest.py: mock URL-lookup responses (with and without relations).

Testing

  • uv run pytest tests/ — 136 passed.
  • uv run ruff format . / uv run ruff check . — clean.
  • uv run ty check — clean.

Backward compatible: includes defaults to None, preserving existing behavior.

zas added 3 commits September 12, 2026 01:31
lookup_by_url (async and sync) now accepts an optional includes argument,
allowing relationship subqueries such as artist-rels/label-rels. This lets
callers resolve which entity a URL belongs to (e.g. find an artist from
their Spotify or Discogs URL) in a single request.

Also adds a relations field to the Url model and tests covering single/
multiple URLs, includes, and relation deserialization.
Add a README example showing how to resolve a URL to its linked entity
(e.g. artist-from-Spotify-URL) via includes, and note inc=<entity>-rels
support on the /url endpoint in the API reference.
Verified against the live API that passing multiple resources to /url
returns a paginated {urls, url-count, url-offset} wrapper rather than a
single URL entity. Update the multi-URL mock and assertion to match.
@zas
zas merged commit 8f20832 into main Sep 11, 2026
15 checks passed
@zas
zas deleted the feature/lookup-by-url-includes branch September 11, 2026 23:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant