Install the musicxmatch_api package
mainInstall the Python wrapper using pip to begin making requests to the Musixmatch API.
pip install musicxmatch_apirepository·main·Indexed 41 days ago
https://github.com/strvm/musicxmatch-apiA Python wrapper for the Musixmatch API providing access to song lyrics, translations, and richsync data. It includes methods for searching artists and tracks, retrieving album information, and accessing track charts by country. The client automatically handles authentication and supports optional proxy configuration for high-volume requests.
Install the Python wrapper using pip to begin making requests to the Musixmatch API.
pip install musicxmatch_apiUse the search_tracks method to search for songs. The returned object can be parsed as JSON.
import json
from musicxmatch_api import MusixMatchAPI
api = MusixMatchAPI()
search = api.search_tracks("skyfall")
print(json.dumps(search, indent=4))Use the search_artist method on a MusixMatchAPI instance to find artists by name. If you are making a high volume of requests, you can pass a proxies argument to the constructor.
from musicxmatch_api import MusixMatchAPI
# If you need to make a high volume of requests, consider using proxies
api = MusixMatchAPI(proxies=proxies)
search = api.search_artist("adele")To get the lyrics for a specific song, use the get_track_lyrics method with a track_id.
Note: The actual lyric text is located within the nested dictionary path: ["message"]["body"]["lyrics"]["lyrics_body"].
from musicxmatch_api import MusixMatchAPI
track_id = 103149239 # Skyfall by Adele
api = MusixMatchAPI(proxies=proxies)
search = api.get_track_lyrics(track_id=track_id)
# The lyrics are in the "lyrics_body" key
lyrics = search["message"]["body"]["lyrics"]["lyrics_body"]Retrieve trending or chart data for artists and tracks by country.
Methods:
get_artist_chart(country="US", page=1): Returns the artist chart for the specified country.get_track_chart(country="US", page=1): Returns the track chart for the specified country.# Get US track charts
track_charts = api.get_track_chart(country="US")Fetch richsync data (synchronized lyrics) from Musixmatch with optional filters.
Parameters:
commontrack_id (str, optional): Musixmatch commontrack ID.track_id (str, optional): Musixmatch track ID.track_isrc (str, optional): ISRC identifier.f_richsync_length (str, optional): Desired sync length in seconds.f_richsync_length_max_deviation (str, optional): Max allowed deviation from sync length.sync_data = api.get_track_richsync(track_id="123", f_richsync_length="180")Retrieve translated lyrics for a specific track.
Parameters:
track_id (str): The Musixmatch track ID.selected_language (str): The language code for the translation.translation = api.get_track_lyrics_translation(track_id="123", selected_language="ES")Use search_tracks to find tracks matching a query. The method automatically filters for tracks that have lyrics (f_has_lyrics=true).
Parameters:
track_query (str): The search term.page (int): The page number for pagination (default: 1).Returns:
dict: A JSON response containing search results.results = api.search_tracks("hey jude", page=1)
print(results)Retrieve detailed information about artists, their albums, and the tracks within those albums.
Methods:
get_artist(artist_id): Returns metadata for a specific artist.get_artist_albums(artist_id, page=1): Returns a paginated list of albums by the artist.get_album(album_id): Returns metadata for a specific album.get_album_tracks(album_id, page=1): Returns a paginated list of tracks within a specific album.# Get artist info
artist = api.get_artist("123")
# Get albums for that artist
album_list = api.get_artist_albums("123")
# Get tracks for a specific album
tracks = api.get_album_tracks("album_id_456")To use the MusixMatch API, instantiate the MusixMatchAPI class. You can optionally provide a proxies dictionary to handle high-volume requests or bypass network restrictions. The client automatically handles authentication by extracting a secret from the MusixMatch web application during initialization.
from musicxmatch_api.main import MusixMatchAPI
# Basic initialization
api = MusixMatchAPI()
# Initialization with proxies
api = MusixMatchAPI(proxies={"http": "http://proxy:port", "https": "http://proxy:port"})Retrieve specific track information or lyrics using either a track_id or a track_isrc.
Methods:
get_track(track_id=None, track_isrc=None): Returns general track metadata.get_track_lyrics(track_id=None, track_isrc=None): Returns the lyrics for the specified track. Note that lyrics are contained in the lyrics_body key of the response.Note: You must provide exactly one of track_id or track_isrc.
# By track_id
lyrics = api.get_track_lyrics(track_id="12345")
# By ISRC
lyrics = api.get_track_lyrics(track_isrc="USUM71923456")Use search_artist to find artists matching a query.
Parameters:
query (str): The artist name or search term.page (int): The page number for pagination (default: 1).Returns:
dict: A JSON response containing artist search results.artists = api.search_artist("The Beatles", page=1)