Load Data from Spotify
to Neon Serverless Postgres
with dlt
in Python
We will be using the dlt PostgreSQL destination to connect to Neon Serverless Postgres. You can get the connection string for your Neon Serverless Postgres database as described in the Neon Serverless Postgres Docs.
Join our Slack community or book a call with our support engineer Violetta.
Spotify
is a digital music, podcast, and video service that provides access to millions of songs and other content from creators worldwide. This guide covers how to load data from Spotify
to Neon Serverless Postgres
using the open-source python library called dlt
. dlt
simplifies the process of data extraction and loading, enabling you to build reliable and scalable applications faster on Neon Serverless Postgres
. For more details about Spotify
, visit Spotify.
dlt
Key Features
- Pipeline Metadata:
dlt
pipelines leverage metadata to provide governance capabilities, including load IDs that enable incremental transformations and data vaulting by tracking data loads and facilitating data lineage and traceability. Read more - Schema Enforcement and Curation:
dlt
empowers users to enforce and curate schemas, ensuring data consistency and quality by defining the structure of normalized data and guiding the processing and loading of data. Read more - Scalability via Iterators, Chunking, and Parallelization:
dlt
offers scalable data extraction by leveraging iterators, chunking, and parallelization techniques, allowing efficient processing of large datasets by breaking them down into manageable chunks. Read more - Implicit Extraction DAGs:
dlt
incorporates the concept of implicit extraction DAGs to handle dependencies between data sources and their transformations automatically, ensuring data consistency and integrity. Read more - Authentication Types for Snowflake: Snowflake destination in
dlt
accepts three authentication types: password authentication, key pair authentication, and external authentication, offering flexibility and security in connecting to your Snowflake database. Read more
Getting started with your pipeline locally
dlt-init-openapi
0. Prerequisites
dlt
and dlt-init-openapi
requires Python 3.9 or higher. Additionally, you need to have the pip
package manager installed, and we recommend using a virtual environment to manage your dependencies. You can learn more about preparing your computer for dlt in our installation reference.
1. Install dlt and dlt-init-openapi
First you need to install the dlt-init-openapi
cli tool.
pip install dlt-init-openapi
The dlt-init-openapi
cli is a powerful generator which you can use to turn any OpenAPI spec into a dlt
source to ingest data from that api. The quality of the generator source is dependent on how well the API is designed and how accurate the OpenAPI spec you are using is. You may need to make tweaks to the generated code, you can learn more about this here.
# generate pipeline
# NOTE: add_limit adds a global limit, you can remove this later
# NOTE: you will need to select which endpoints to render, you
# can just hit Enter and all will be rendered.
dlt-init-openapi spotify --url https://raw.githubusercontent.com/dlt-hub/dlt-init-openapi/devel/tests/cases/original_specs/spotify.json --global-limit 2
cd spotify_pipeline
# install generated requirements
pip install -r requirements.txt
The last command will install the required dependencies for your pipeline. The dependencies are listed in the requirements.txt
:
dlt>=0.4.12
You now have the following folder structure in your project:
spotify_pipeline/
├── .dlt/
│ ├── config.toml # configs for your pipeline
│ └── secrets.toml # secrets for your pipeline
├── rest_api/ # The rest api verified source
│ └── ...
├── spotify/
│ └── __init__.py # TODO: possibly tweak this file
├── spotify_pipeline.py # your main pipeline script
├── requirements.txt # dependencies for your pipeline
└── .gitignore # ignore files for git (not required)
1.1. Tweak spotify/__init__.py
This file contains the generated configuration of your rest_api. You can continue with the next steps and leave it as is, but you might want to come back here and make adjustments if you need your rest_api
source set up in a different way. The generated file for the spotify source will look like this:
Click to view full file (1102 lines)
from typing import List
import dlt
from dlt.extract.source import DltResource
from rest_api import rest_api_source
from rest_api.typing import RESTAPIConfig
@dlt.source(name="spotify_source", max_table_nesting=2)
def spotify_source(
base_url: str = dlt.config.value,
) -> List[DltResource]:
# source configuration
source_config: RESTAPIConfig = {
"client": {
"base_url": base_url,
"paginator": {
"type":
"offset",
"limit":
50,
"offset_param":
"offset",
"limit_param":
"limit",
"total_path":
"total",
},
},
"resources":
[
# Get Spotify catalog information for a single album.
{
"name": "get_an_album",
"table_name": "album",
"endpoint": {
"data_selector": "available_markets",
"path": "/albums/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "get_multiple_albums",
"field": "id",
},
},
"paginator": {
"type":
"json_response",
"next_url_path":
"tracks.next",
},
}
},
# Get Spotify catalog information for multiple albums identified by their Spotify IDs.
{
"name": "get_multiple_albums",
"table_name": "album_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "albums",
"path": "/albums",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information for several artists based on their Spotify IDs.
{
"name": "get_multiple_artists",
"table_name": "artist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "artists",
"path": "/artists",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Get Spotify catalog information for a single artist identified by their unique Spotify ID.
{
"name": "get_an_artist",
"table_name": "artist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "$",
"path": "/artists/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "get_multiple_artists",
"field": "id",
},
},
}
},
# Get Spotify catalog information about artists similar to a given artist. Similarity is based on analysis of the Spotify community's [listening history](http://news.spotify.com/se/2010/02/03/related-artists/).
{
"name": "get_an_artists_related_artists",
"table_name": "artist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "artists",
"path": "/artists/{id}/related-artists",
"params": {
"id": {
"type": "resolve",
"resource": "get_multiple_artists",
"field": "id",
},
},
}
},
# Get the current user's followed artists.
{
"name": "get_followed",
"table_name": "artist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "artists.items",
"path": "/me/following",
"paginator": {
"type":
"json_response",
"next_url_path":
"artists.next",
},
}
},
# Get information about the user’s current playback state, including track or episode, progress, and active device.
{
"name": "get_information_about_the_users_current_playback",
"table_name": "artist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "item.artists",
"path": "/me/player",
"params": {
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
# "additional_types": "OPTIONAL_CONFIG",
},
}
},
# Get the object currently being played on the user's Spotify account.
{
"name": "get_the_users_currently_playing_track",
"table_name": "artist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "item.artists",
"path": "/me/player/currently-playing",
"params": {
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
# "additional_types": "OPTIONAL_CONFIG",
},
}
},
# Get the current user's top artists based on calculated affinity.
{
"name": "get_users_top_artists",
"table_name": "artist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "items",
"path": "/me/top/artists",
"params": {
# the parameters below can optionally be configured
# "time_range": "medium_term",
},
}
},
# Get a low-level audio analysis for a track in the Spotify catalog. The audio analysis describes the track’s structure and musical content, including rhythm, pitch, and timbre.
{
"name": "get_audio_analysis",
"table_name": "audio_analysis_object",
"endpoint": {
"data_selector": "$",
"path": "/audio-analysis/{id}",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
},
}
},
# Get audio features for multiple tracks based on their Spotify IDs.
{
"name": "get_several_audio_features",
"table_name": "audio_features_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "audio_features",
"path": "/audio-features",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Get audio feature information for a single track identified by its unique Spotify ID.
{
"name": "get_audio_features",
"table_name": "audio_features_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "$",
"path": "/audio-features/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "get_several_audio_features",
"field": "id",
},
},
}
},
# Get Spotify catalog information for several audiobooks identified by their Spotify IDs.<br /> **Note: Audiobooks are only available for the US, UK, Ireland, New Zealand and Australia markets.**
{
"name": "get_multiple_audiobooks",
"table_name": "audiobook_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "audiobooks",
"path": "/audiobooks",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information for a single audiobook.<br /> **Note: Audiobooks are only available for the US, UK, Ireland, New Zealand and Australia markets.**
{
"name": "get_an_audiobook",
"table_name": "author_object",
"endpoint": {
"data_selector": "authors",
"path": "/audiobooks/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "get_multiple_audiobooks",
"field": "id",
},
},
"paginator": {
"type":
"json_response",
"next_url_path":
"chapters.next",
},
}
},
# Retrieve a list of available genres seed parameter values for [recommendations](/documentation/web-api/reference/#/operations/get-recommendations).
{
"name": "get_recommendation_genres",
"table_name": "available_genre_seed",
"endpoint": {
"data_selector": "genres",
"path": "/recommendations/available-genre-seeds",
}
},
# Get a list of categories used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
{
"name": "get_categories",
"table_name": "category_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "categories.items",
"path": "/browse/categories",
"params": {
# the parameters below can optionally be configured
# "country": "OPTIONAL_CONFIG",
# "locale": "OPTIONAL_CONFIG",
},
"paginator": {
"type":
"offset",
"limit":
50,
"offset_param":
"offset",
"limit_param":
"limit",
"total_path":
"categories.total",
},
}
},
# Get a single category used to tag items in Spotify (on, for example, the Spotify player’s “Browse” tab).
{
"name": "get_a_category",
"table_name": "category_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "$",
"path": "/browse/categories/{category_id}",
"params": {
"category_id": {
"type": "resolve",
"resource": "get_categories",
"field": "id",
},
# the parameters below can optionally be configured
# "country": "OPTIONAL_CONFIG",
# "locale": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information for several chapters identified by their Spotify IDs.<br /> **Note: Chapters are only available for the US, UK, Ireland, New Zealand and Australia markets.**
{
"name": "get_several_chapters",
"table_name": "chapter_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "chapters",
"path": "/chapters",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information for a single chapter.<br /> **Note: Chapters are only available for the US, UK, Ireland, New Zealand and Australia markets.**
{
"name": "get_a_chapter",
"table_name": "chapter_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "$",
"path": "/chapters/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "get_several_chapters",
"field": "id",
},
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Check if one or more albums is already saved in the current Spotify user's 'Your Music' library.
{
"name": "check_users_saved_albums",
"table_name": "contain",
"endpoint": {
"data_selector": "$",
"path": "/me/albums/contains",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Check if one or more audiobooks are already saved in the current Spotify user's library.
{
"name": "check_users_saved_audiobooks",
"table_name": "contain",
"endpoint": {
"data_selector": "$",
"path": "/me/audiobooks/contains",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Check if one or more episodes is already saved in the current Spotify user's 'Your Episodes' library.
{
"name": "check_users_saved_episodes",
"table_name": "contain",
"endpoint": {
"data_selector": "$",
"path": "/me/episodes/contains",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Check to see if the current user is following one or more artists or other Spotify users.
{
"name": "check_current_user_follows",
"table_name": "contain",
"endpoint": {
"data_selector": "$",
"path": "/me/following/contains",
"params": {
"type": "FILL_ME_IN", # TODO: fill in required query parameter
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Check if one or more shows is already saved in the current Spotify user's library.
{
"name": "check_users_saved_shows",
"table_name": "contain",
"endpoint": {
"data_selector": "$",
"path": "/me/shows/contains",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Check if one or more tracks is already saved in the current Spotify user's 'Your Music' library.
{
"name": "check_users_saved_tracks",
"table_name": "contain",
"endpoint": {
"data_selector": "$",
"path": "/me/tracks/contains",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Check to see if one or more Spotify users are following a specified playlist.
{
"name": "check_if_user_follows_playlist",
"table_name": "contain",
"endpoint": {
"data_selector": "$",
"path": "/playlists/{playlist_id}/followers/contains",
"params": {
"playlist_id": "FILL_ME_IN", # TODO: fill in required path parameter
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
},
}
},
# Get information about a user’s available devices.
{
"name": "get_a_users_available_devices",
"table_name": "device_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "devices",
"path": "/me/player/devices",
}
},
# Get Spotify catalog information for several episodes based on their Spotify IDs.
{
"name": "get_multiple_episodes",
"table_name": "episode_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "episodes",
"path": "/episodes",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information for a single episode identified by its unique Spotify ID.
{
"name": "get_an_episode",
"table_name": "episode_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "$",
"path": "/episodes/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "get_multiple_episodes",
"field": "id",
},
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get detailed profile information about the current user (including the current user's username).
{
"name": "get_current_users_profile",
"table_name": "image_object",
"endpoint": {
"data_selector": "images",
"path": "/me",
}
},
# Get a playlist owned by a Spotify user.
{
"name": "get_playlist",
"table_name": "image_object",
"endpoint": {
"data_selector": "images",
"path": "/playlists/{playlist_id}",
"params": {
"playlist_id": "FILL_ME_IN", # TODO: fill in required path parameter
},
"paginator": {
"type":
"json_response",
"next_url_path":
"tracks.next",
},
}
},
# Get the current image associated with a specific playlist.
{
"name": "get_playlist_cover",
"table_name": "image_object",
"endpoint": {
"data_selector": "$",
"path": "/playlists/{playlist_id}/images",
"params": {
"playlist_id": "FILL_ME_IN", # TODO: fill in required path parameter
},
}
},
# Get the list of markets where Spotify is available.
{
"name": "get_available_markets",
"table_name": "market",
"endpoint": {
"data_selector": "markets",
"path": "/markets",
}
},
# Get tracks from the current user's recently played tracks. _**Note**: Currently doesn't support podcast episodes._
{
"name": "get_recently_played",
"table_name": "play_history_object",
"endpoint": {
"data_selector": "items",
"path": "/me/player/recently-played",
"paginator": {
"type":
"json_response",
"next_url_path":
"next",
},
}
},
# Get full details of the items of a playlist owned by a Spotify user.
{
"name": "get_playlists_tracks",
"table_name": "playlist_track_object",
"endpoint": {
"data_selector": "items",
"path": "/playlists/{playlist_id}/tracks",
"params": {
"playlist_id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
# "fields": "OPTIONAL_CONFIG",
# "additional_types": "OPTIONAL_CONFIG",
},
"paginator": {
"type":
"offset",
"limit":
100,
"offset_param":
"offset",
"limit_param":
"limit",
"total_path":
"total",
},
}
},
# Get public profile information about a Spotify user.
{
"name": "get_users_profile",
"table_name": "public_user_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "$",
"path": "/users/{user_id}",
"params": {
"user_id": "FILL_ME_IN", # TODO: fill in required path parameter
},
}
},
# Get the list of objects that make up the user's queue.
{
"name": "get_queue",
"table_name": "queue",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "queue",
"path": "/me/player/queue",
}
},
# Recommendations are generated based on the available information for a given seed entity and matched against similar artists and tracks. If there is sufficient information about the provided seeds, a list of tracks will be returned together with pool size details. For artists and tracks that are very new or obscure there might not be enough data to generate a list of tracks.
{
"name": "get_recommendations",
"table_name": "recommendation_seed_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "seeds",
"path": "/recommendations",
"params": {
# the parameters below can optionally be configured
# "limit": "20",
# "market": "OPTIONAL_CONFIG",
# "seed_artists": "OPTIONAL_CONFIG",
# "seed_genres": "OPTIONAL_CONFIG",
# "seed_tracks": "OPTIONAL_CONFIG",
# "min_acousticness": "OPTIONAL_CONFIG",
# "max_acousticness": "OPTIONAL_CONFIG",
# "target_acousticness": "OPTIONAL_CONFIG",
# "min_danceability": "OPTIONAL_CONFIG",
# "max_danceability": "OPTIONAL_CONFIG",
# "target_danceability": "OPTIONAL_CONFIG",
# "min_duration_ms": "OPTIONAL_CONFIG",
# "max_duration_ms": "OPTIONAL_CONFIG",
# "target_duration_ms": "OPTIONAL_CONFIG",
# "min_energy": "OPTIONAL_CONFIG",
# "max_energy": "OPTIONAL_CONFIG",
# "target_energy": "OPTIONAL_CONFIG",
# "min_instrumentalness": "OPTIONAL_CONFIG",
# "max_instrumentalness": "OPTIONAL_CONFIG",
# "target_instrumentalness": "OPTIONAL_CONFIG",
# "min_key": "OPTIONAL_CONFIG",
# "max_key": "OPTIONAL_CONFIG",
# "target_key": "OPTIONAL_CONFIG",
# "min_liveness": "OPTIONAL_CONFIG",
# "max_liveness": "OPTIONAL_CONFIG",
# "target_liveness": "OPTIONAL_CONFIG",
# "min_loudness": "OPTIONAL_CONFIG",
# "max_loudness": "OPTIONAL_CONFIG",
# "target_loudness": "OPTIONAL_CONFIG",
# "min_mode": "OPTIONAL_CONFIG",
# "max_mode": "OPTIONAL_CONFIG",
# "target_mode": "OPTIONAL_CONFIG",
# "min_popularity": "OPTIONAL_CONFIG",
# "max_popularity": "OPTIONAL_CONFIG",
# "target_popularity": "OPTIONAL_CONFIG",
# "min_speechiness": "OPTIONAL_CONFIG",
# "max_speechiness": "OPTIONAL_CONFIG",
# "target_speechiness": "OPTIONAL_CONFIG",
# "min_tempo": "OPTIONAL_CONFIG",
# "max_tempo": "OPTIONAL_CONFIG",
# "target_tempo": "OPTIONAL_CONFIG",
# "min_time_signature": "OPTIONAL_CONFIG",
# "max_time_signature": "OPTIONAL_CONFIG",
# "target_time_signature": "OPTIONAL_CONFIG",
# "min_valence": "OPTIONAL_CONFIG",
# "max_valence": "OPTIONAL_CONFIG",
# "target_valence": "OPTIONAL_CONFIG",
},
}
},
# Get a list of the albums saved in the current Spotify user's 'Your Music' library.
{
"name": "get_users_saved_albums",
"table_name": "saved_album_object",
"endpoint": {
"data_selector": "items",
"path": "/me/albums",
"params": {
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get a list of the audiobooks saved in the current Spotify user's 'Your Music' library.
{
"name": "get_users_saved_audiobooks",
"table_name": "saved_audiobook_object",
"endpoint": {
"data_selector": "items",
"path": "/me/audiobooks",
}
},
# Get a list of the episodes saved in the current Spotify user's library.
{
"name": "get_users_saved_episodes",
"table_name": "saved_episode_object",
"endpoint": {
"data_selector": "items",
"path": "/me/episodes",
"params": {
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get a list of shows saved in the current Spotify user's library. Optional parameters can be used to limit the number of shows returned.
{
"name": "get_users_saved_shows",
"table_name": "saved_show_object",
"endpoint": {
"data_selector": "items",
"path": "/me/shows",
}
},
# Get a list of the songs saved in the current Spotify user's 'Your Music' library.
{
"name": "get_users_saved_tracks",
"table_name": "saved_track_object",
"endpoint": {
"data_selector": "items",
"path": "/me/tracks",
"params": {
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information for a single show identified by its unique Spotify ID.
{
"name": "get_a_show",
"table_name": "show",
"endpoint": {
"data_selector": "available_markets",
"path": "/shows/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "get_multiple_shows",
"field": "id",
},
},
"paginator": {
"type":
"json_response",
"next_url_path":
"episodes.next",
},
}
},
# Get Spotify catalog information about an artist's albums.
{
"name": "get_an_artists_albums",
"table_name": "simplified_album_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "items",
"path": "/artists/{id}/albums",
"params": {
"id": {
"type": "resolve",
"resource": "get_multiple_artists",
"field": "id",
},
# the parameters below can optionally be configured
# "include_groups": "OPTIONAL_CONFIG",
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get a list of new album releases featured in Spotify (shown, for example, on a Spotify player’s “Browse” tab).
{
"name": "get_new_releases",
"table_name": "simplified_album_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "albums.items",
"path": "/browse/new-releases",
"params": {
# the parameters below can optionally be configured
# "country": "OPTIONAL_CONFIG",
},
"paginator": {
"type":
"offset",
"limit":
50,
"offset_param":
"offset",
"limit_param":
"limit",
"total_path":
"albums.total",
},
}
},
# Get Spotify catalog information about albums, artists, playlists, tracks, shows, episodes or audiobooks that match a keyword string.<br /> **Note: Audiobooks are only available for the US, UK, Ireland, New Zealand and Australia markets.**
{
"name": "search",
"table_name": "simplified_album_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "albums.items",
"path": "/search",
"params": {
"q": "FILL_ME_IN", # TODO: fill in required query parameter
"type": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
# "include_external": "OPTIONAL_CONFIG",
},
"paginator": {
"type":
"offset",
"limit":
50,
"offset_param":
"offset",
"limit_param":
"limit",
"total_path":
"albums.total",
},
}
},
# Get Spotify catalog information about an audiobook's chapters.<br /> **Note: Audiobooks are only available for the US, UK, Ireland, New Zealand and Australia markets.**
{
"name": "get_audiobook_chapters",
"table_name": "simplified_chapter_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "items",
"path": "/audiobooks/{id}/chapters",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information about an show’s episodes. Optional parameters can be used to limit the number of episodes returned.
{
"name": "get_a_shows_episodes",
"table_name": "simplified_episode_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "items",
"path": "/shows/{id}/episodes",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get a list of Spotify playlists tagged with a particular category.
{
"name": "get_a_categories_playlists",
"table_name": "simplified_playlist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "playlists.items",
"path": "/browse/categories/{category_id}/playlists",
"params": {
"category_id": {
"type": "resolve",
"resource": "get_categories",
"field": "id",
},
# the parameters below can optionally be configured
# "country": "OPTIONAL_CONFIG",
},
"paginator": {
"type":
"offset",
"limit":
50,
"offset_param":
"offset",
"limit_param":
"limit",
"total_path":
"playlists.total",
},
}
},
# Get a list of Spotify featured playlists (shown, for example, on a Spotify player's 'Browse' tab).
{
"name": "get_featured_playlists",
"table_name": "simplified_playlist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "playlists.items",
"path": "/browse/featured-playlists",
"params": {
# the parameters below can optionally be configured
# "country": "OPTIONAL_CONFIG",
# "locale": "OPTIONAL_CONFIG",
# "timestamp": "OPTIONAL_CONFIG",
},
"paginator": {
"type":
"offset",
"limit":
50,
"offset_param":
"offset",
"limit_param":
"limit",
"total_path":
"playlists.total",
},
}
},
# Get a list of the playlists owned or followed by the current Spotify user.
{
"name": "get_a_list_of_current_users_playlists",
"table_name": "simplified_playlist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "items",
"path": "/me/playlists",
}
},
# Get a list of the playlists owned or followed by a Spotify user.
{
"name": "get_list_users_playlists",
"table_name": "simplified_playlist_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "items",
"path": "/users/{user_id}/playlists",
"params": {
"user_id": "FILL_ME_IN", # TODO: fill in required path parameter
},
}
},
# Get Spotify catalog information for several shows based on their Spotify IDs.
{
"name": "get_multiple_shows",
"table_name": "simplified_show_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "shows",
"path": "/shows",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information about an album’s tracks. Optional parameters can be used to limit the number of tracks returned.
{
"name": "get_an_albums_tracks",
"table_name": "simplified_track_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "items",
"path": "/albums/{id}/tracks",
"params": {
"id": "FILL_ME_IN", # TODO: fill in required path parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information about an artist's top tracks by country.
{
"name": "get_an_artists_top_tracks",
"table_name": "track_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "tracks",
"path": "/artists/{id}/top-tracks",
"params": {
"id": {
"type": "resolve",
"resource": "get_multiple_artists",
"field": "id",
},
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get the current user's top tracks based on calculated affinity.
{
"name": "get_users_top_tracks",
"table_name": "track_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "items",
"path": "/me/top/tracks",
"params": {
# the parameters below can optionally be configured
# "time_range": "medium_term",
},
}
},
# Get Spotify catalog information for multiple tracks based on their Spotify IDs.
{
"name": "get_several_tracks",
"table_name": "track_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "tracks",
"path": "/tracks",
"params": {
"ids": "FILL_ME_IN", # TODO: fill in required query parameter
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
# Get Spotify catalog information for a single track identified by its unique Spotify ID.
{
"name": "get_track",
"table_name": "track_object",
"primary_key": "id",
"write_disposition": "merge",
"endpoint": {
"data_selector": "$",
"path": "/tracks/{id}",
"params": {
"id": {
"type": "resolve",
"resource": "get_several_tracks",
"field": "id",
},
# the parameters below can optionally be configured
# "market": "OPTIONAL_CONFIG",
},
}
},
]
}
return rest_api_source(source_config)
2. Configuring your source and destination credentials
dlt-init-openapi
will try to detect which authentication mechanism (if any) is used by the API in question and add a placeholder in your secrets.toml
.
The dlt
cli will have created a .dlt
directory in your project folder. This directory contains a config.toml
file and a secrets.toml
file that you can use to configure your pipeline. The automatically created version of these files look like this:
generated config.toml
[runtime]
log_level="INFO"
[sources.spotify]
# Base URL for the API
base_url = "https://api.spotify.com/v1"
generated secrets.toml
[sources.spotify]
# secrets for your spotify source
# example_api_key = "example value"
2.1. Adjust the generated code to your usecase
At this time, the dlt-init-openapi
cli tool will always create pipelines that load to a local duckdb
instance. Switching to a different destination is trivial, all you need to do is change the destination
parameter in spotify_pipeline.py
to postgres and supply the credentials as outlined in the destination doc linked below.
3. Running your pipeline for the first time
The dlt
cli has also created a main pipeline script for you at spotify_pipeline.py
, as well as a folder spotify
that contains additional python files for your source. These files are your local copies which you can modify to fit your needs. In some cases you may find that you only need to do small changes to your pipelines or add some configurations, in other cases these files can serve as a working starting point for your code, but will need to be adjusted to do what you need them to do.
The main pipeline script will look something like this:
import dlt
from spotify import spotify_source
if __name__ == "__main__":
pipeline = dlt.pipeline(
pipeline_name="spotify_pipeline",
destination='duckdb',
dataset_name="spotify_data",
progress="log",
export_schema_path="schemas/export"
)
source = spotify_source()
info = pipeline.run(source)
print(info)
Provided you have set up your credentials, you can run your pipeline like a regular python script with the following command:
python spotify_pipeline.py
4. Inspecting your load result
You can now inspect the state of your pipeline with the dlt
cli:
dlt pipeline spotify_pipeline info
You can also use streamlit to inspect the contents of your Neon Serverless Postgres
destination for this:
# install streamlit
pip install streamlit
# run the streamlit app for your pipeline with the dlt cli:
dlt pipeline spotify_pipeline show
5. Next steps to get your pipeline running in production
One of the beauties of dlt
is, that we are just a plain Python library, so you can run your pipeline in any environment that supports Python >= 3.8. We have a couple of helpers and guides in our docs to get you there:
The Deploy section will show you how to deploy your pipeline to
- Deploy with GitHub Actions: Automate your pipeline deployment using GitHub Actions. Follow the detailed guide here.
- Deploy with Airflow and Google Composer: Learn how to deploy your pipeline with Airflow and Google Composer by following the steps here.
- Deploy with Google Cloud Functions: Use Google Cloud Functions to deploy your pipeline effortlessly. Check out the guide here.
- Explore Other Deployment Options: Discover various other methods to deploy your pipeline by visiting the comprehensive list here.
The running in production section will teach you about:
- How to Monitor your pipeline: Learn how to effectively monitor your
dlt
pipeline in production to ensure smooth and reliable operation. Visit How to Monitor your pipeline. - Set up alerts: Set up alerts to get notified about any issues or important events in your
dlt
pipeline. Check out the guide on Set up alerts. - And set up tracing: Implement tracing in your
dlt
pipeline to gain insights into the performance and behavior of your data workflows. Read more on And set up tracing.
Available Sources and Resources
For this verified source the following sources and resources are available
Source Spotify
Spotify source provides data on tracks, albums, playlists, users, devices, and audio analysis.
Resource Name | Write Disposition | Description |
---|---|---|
image_object | append | Represents image data associated with various Spotify entities. |
simplified_track_object | append | Contains simplified information about a Spotify track. |
device_object | append | Information about a user's Spotify devices. |
saved_episode_object | append | Details of episodes saved by the user. |
simplified_playlist_object | append | Simplified details of a Spotify playlist. |
audio_analysis_object | append | Detailed audio analysis for a single track. |
chapter_object | append | Represents chapters in audiobooks or podcasts. |
saved_track_object | append | Information about tracks saved by the user. |
category_object | append | Represents categories or genres available on Spotify. |
public_user_object | append | Public profile information of a Spotify user. |
show | append | Information about a show (podcast or other). |
artist_object | append | Details about an artist on Spotify. |
saved_audiobook_object | append | Information about audiobooks saved by the user. |
simplified_album_object | append | Simplified details of a Spotify album. |
contain | append | General container for various Spotify data. |
queue | append | Details about the user's current playback queue. |
simplified_chapter_object | append | Simplified information about chapters in audiobooks or podcasts. |
play_history_object | append | User's play history data. |
album | append | Information about a specific album. |
simplified_show_object | append | Simplified details of a show (podcast or other). |
author_object | append | Information about authors of audiobooks or other content. |
audio_features_object | append | Acoustic features of a track. |
album_object | append | Detailed information about an album. |
episode_object | append | Information about a specific episode of a show. |
recommendation_seed_object | append | Seed data used for generating recommendations. |
market | append | Market or region information for Spotify content. |
playlist_track_object | append | Information about tracks in a playlist. |
saved_album_object | append | Details of albums saved by the user. |
simplified_episode_object | append | Simplified information about episodes of a show. |
track_object | append | Detailed information about a Spotify track. |
available_genre_seed | append | Available genre seeds for recommendations. |
audiobook_object | append | Detailed information about an audiobook. |
saved_show_object | append | Information about shows saved by the user. |
Additional pipeline guides
- Load data from Mux to Azure Cloud Storage in python with dlt
- Load data from The Local Filesystem to Databricks in python with dlt
- Load data from Keap to BigQuery in python with dlt
- Load data from Star Trek to Supabase in python with dlt
- Load data from Zuora to The Local Filesystem in python with dlt
- Load data from Keap to AlloyDB in python with dlt
- Load data from Shopify to Neon Serverless Postgres in python with dlt
- Load data from Bitbucket to AlloyDB in python with dlt
- Load data from Box Platform API to AlloyDB in python with dlt
- Load data from Salesforce to DuckDB in python with dlt