Repository navigation
Add includes support to lookup_by_url - #6
Merged
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an optional
includesargument tolookup_by_url(both asyncMusicBrainzClientandSyncMusicBrainzClient), enabling relationship subqueries on the/urlendpoint.Motivation
lookup_by_urlpreviously only returned the bare URL entity (its MBID and resource), with no way to discover which entities the URL is linked to. The MusicBrainz/urlendpoint supportsinc=<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, addsinc=param.SyncMusicBrainzClient.lookup_by_url(*urls, includes=None)— sync, same.Urlmodel gains an optionalrelations: list[MBModel] | Nonefield (consistent with the existingWork/Eventmodels) for typed access.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:Urldeserialization 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:
includesdefaults toNone, preserving existing behavior.