Overview
TheLibraryService (sync) and AsyncLibraryService (async) provide methods for managing items in the current user’s Spotify library. This service offers a unified interface for saving, removing, and checking the save status of various content types using Spotify URIs.
Both sync and async versions are available. Import
LibraryService for sync operations or AsyncLibraryService for async operations.All methods require appropriate user authorization scopes (user-library-modify or user-library-read).Methods
save_items
Save one or more items to the current user’s library.Spotify URIs to save. Maximum of 40 URIs per request. URIs can be for albums, tracks, episodes, shows, or audiobooks.
None - This method does not return a value.
Raises:
ValueErrorifurisis empty, contains empty values, or exceeds 40 items.
Requires the
user-library-modify scope.remove_items
Remove one or more items from the current user’s library.Spotify URIs to remove. Maximum of 40 URIs per request. URIs can be for albums, tracks, episodes, shows, or audiobooks.
None - This method does not return a value.
Raises:
ValueErrorifurisis empty, contains empty values, or exceeds 40 items.
Requires the
user-library-modify scope.check_contains
Check if items are saved in the current user’s library.Spotify URIs to check. Maximum of 40 URIs per request. URIs can be for albums, tracks, episodes, shows, or audiobooks.
list[bool] - A list of boolean values aligned to the input URIs, where True indicates the item is saved in the library.
Raises:
ValueErrorifurisis empty, contains empty values, exceeds 40 items, or the response shape is notlist[bool].
Requires the
user-library-read scope.URI Format
Spotify URIs follow the format:spotify:{type}:{id}
Supported types include:
track- Music tracksalbum- Albumsepisode- Podcast episodesshow- Podcast showsaudiobook- Audiobooks
Example URIs
Validation Rules
All methods validate URIs according to these rules:- The
urislist cannot be empty - Maximum of 40 URIs per request
- URIs cannot contain empty strings or
Nonevalues - URIs must follow the Spotify URI format
Required Scopes
Required for
save_items() and remove_items() methods.Required for
check_contains() method.See Also
- Albums Service - Album-specific library operations
- Episodes Service - Episode-specific library operations
- Authentication - OAuth scopes and authorization flows