[GH-ISSUE #496] How to search for artists for their genres? #296

Closed
opened 2026-02-27 23:21:51 +03:00 by kerem · 2 comments
Owner

Originally created by @psenoglu on GitHub (May 22, 2020).
Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/496

Hello,

I am trying to get the genres of the artist with the sp search.
Spotify provides this information already with their Search for an Item APIs. Since I have already tried with the following code, there comes no genre in the output.

The code I used:

from spotipy.oauth2 import SpotifyClientCredentials
import spotipy
import sys
import pprint

if len(sys.argv) > 1:
    search_str = sys.argv[1]
else:
    search_str = 'Weezer'

sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials())
result = sp.search(search_str)
pprint.pprint(result)

I am really a beginner so I appreciate any help.

Thanks in advance.

Originally created by @psenoglu on GitHub (May 22, 2020). Original GitHub issue: https://github.com/spotipy-dev/spotipy/issues/496 Hello, I am trying to get the genres of the artist with the sp **search**. Spotify provides this information already with their Search for an Item APIs. Since I have already tried with the following code, there comes no genre in the output. The code I used: ``` from spotipy.oauth2 import SpotifyClientCredentials import spotipy import sys import pprint if len(sys.argv) > 1: search_str = sys.argv[1] else: search_str = 'Weezer' sp = spotipy.Spotify(client_credentials_manager=SpotifyClientCredentials()) result = sp.search(search_str) pprint.pprint(result) ``` I am really a beginner so I appreciate any help. Thanks in advance.
kerem 2026-02-27 23:21:51 +03:00
  • closed this issue
  • added the
    question
    label
Author
Owner

@ritiek commented on GitHub (May 22, 2020):

Hi! You need to explicitly specify in sp.search that you wish to search for artists (otherwise the search will default to tracks). For example:

# Search "Green Day" in artists and return only the first result
result = sp.search("green day", limit=1, type="artist")
artists = result["artists"]
# Display genres associated with the first search result
print(artists["items"][0]["genres"])
<!-- gh-comment-id:632893640 --> @ritiek commented on GitHub (May 22, 2020): Hi! You need to explicitly specify in [`sp.search`](https://spotipy.readthedocs.io/en/2.12.0/#spotipy.client.Spotify.search) that you wish to search for artists (otherwise the search will default to tracks). For example: ```python # Search "Green Day" in artists and return only the first result result = sp.search("green day", limit=1, type="artist") artists = result["artists"] # Display genres associated with the first search result print(artists["items"][0]["genres"]) ```
Author
Owner

@psenoglu commented on GitHub (May 22, 2020):

thanks a lot @ritiek

<!-- gh-comment-id:632894913 --> @psenoglu commented on GitHub (May 22, 2020): thanks a lot @ritiek
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/spotipy#296
No description provided.