tekore

Package

  • Release notes
  • Reference

Guide

  • Getting started
  • Authorisation guide
  • Advanced usage
  • Examples
    • Artist follower
    • Async server
    • Authenticating server
    • Creating local scripts
    • Discord bot
    • Snippets
      • Albums of user’s top artist
      • Analyse track from playlist
      • Follow with a search
      • Follow category playlist
      • Play saved album
      • Recommended tracks playlist
      • Related artists of user’s top artist
      • Scrape playlist artists
      • Tracks of a new release
  • Additional resources
tekore
  • Examples
  • Snippets
  • Recommended tracks playlist
  • View page source

Recommended tracks playlist

The following script recommends songs based on your top tracks and creates a playlist from them.

It assumes that your credentials are saved in the environment and you have used Spotify enough to have top tracks.

import tekore as tk

conf = tk.config_from_environment()
scope = tk.scope.user_top_read + tk.scope.playlist_modify_private
token = tk.prompt_for_user_token(*conf, scope=scope)

spotify = tk.Spotify(token)
top_tracks = spotify.current_user_top_tracks(limit=5).items
top_track_ids = [t.id for t in top_tracks]
recommendations = spotify.recommendations(track_ids=top_track_ids).tracks

user = spotify.current_user()
playlist = spotify.playlist_create(
    user.id,
    'Tekore Recommendations',
    public=False,
    description='Recommendations based on your top tracks <3'
)
uris = [t.uri for t in recommendations]
spotify.playlist_add(playlist.id, uris=uris)
Previous Next

© Copyright 2019-2026, Felix Hildén.

Built with Sphinx using a theme provided by Read the Docs.