Concepts behind the examples¶
Read this alongside the code. Each topic links back to a complete script.
An asynchronous request¶
await suspends the current coroutine until its awaited operation completes. Other scheduled tasks can run while it waits for I/O. It does not mean every operation is automatically concurrent. Use asyncio.run only when there is no running event loop.
In code: Search for tracks · Search from a synchronous script
Client ownership and connection reuse¶
A client scope owns the connections it creates. Use Public for an isolated request; use Catalogue when several requests belong to one asynchronous application. A synchronous script can use SyncCatalogue. A function borrowing a client should leave cleanup to its owner.
In code: Search for tracks · Search from a synchronous script · Reuse a catalogue client · Read playlist occurrences
Resource identity¶
An identifier names a resource; a syntactically valid Spotify URI does not establish that the resource exists or is accessible. Parse links locally before requesting metadata.
In code: Normalize a Spotify link · Inspect an album
Typed results and serialization¶
A result model exposes fields already returned by a request. Reading a field does not fetch more information. to_dict converts supported models to Python values; json.dumps encodes those values. A successful empty collection is valid.
In code: Search for tracks · Reuse a catalogue client · Inspect an album · Export typed results to JSON · Export public playlist metadata · Read your top tracks
Playlist occurrence identity¶
One track may appear in a playlist more than once. A playlist occurrence ID distinguishes individual entries. An unavailable entry can still occupy a position. Iterate occurrences and close the generator when you stop early.
In code: Export public playlist metadata · Read playlist occurrences
Authenticated account scope¶
Private requests operate with an authorized session. Keep session credentials out of shared files and logs. Read-only statistics do not require a mutation. Check supported behavior before issuing account changes.
In code: Read your top tracks
Apply resource identity and typed results.
Continue your examplesSpotAPI 2.1.3 · Source revision 56ae951 · Report a documentation issue · Identifier converter · Sponsor our documentation