15 releases (8 breaking)

0.10.0 Jul 1, 2020
0.9.0 Feb 27, 2020
0.8.0 Jan 30, 2020
0.7.0 Oct 11, 2019
0.1.2 Mar 13, 2018

#1 in Audio

Download history 1146/week @ 2020-06-01 1021/week @ 2020-06-08 846/week @ 2020-06-15 1005/week @ 2020-06-22 1078/week @ 2020-06-29 1016/week @ 2020-07-06 1601/week @ 2020-07-13 1943/week @ 2020-07-20 1304/week @ 2020-07-27 1176/week @ 2020-08-03 1195/week @ 2020-08-10 1258/week @ 2020-08-17 1295/week @ 2020-08-24 1106/week @ 2020-08-31 1063/week @ 2020-09-07 953/week @ 2020-09-14

4,790 downloads per month
Used in less than 12 crates

MIT license


Crates.io Docs

Rspotify - a Rust client for The Spotify Web API


This crate is heavily inspired by spotipy- A spotify api wrapper implemented in Python


Rspotify is a lightweight wrapper for the Spotify Web API It includes helper functions for all Spotify's endpoints, such as fetching metadata (search and look-up of albums, artists, tracks, playlists, new releases) and user's information (follow users, artists and playlists, and saved tracks management).


rspotify supports all of the features of the Spotify Web API including access to all end points, and support for user authorization, notes that before accessing to any end points, you need to be authorized. For details on the capabilities you are encouraged to review the Spotify Web Endpoint Reference documentation.

Nowaday, thanks to reqwest, rspotify now supports system proxy by default. Reqwest System proxies look in environment variables to set HTTP or HTTPS proxies. HTTP_PROXY or http_proxy provide http proxies for http connections while HTTPS_PROXY or https_proxy provide HTTPS proxies for HTTPS connections.(Notes that reqwest system proxy doesn't support socks proxy for now, check this issue for more details)


cargo install rspotify

Or you could get it from github

Getting Started


Since all methods require user authorization now, you will need to generate an authorization token that indicates that the user has granted permission for your application to perform the given task. You will need to register your app to get the credentials necessary to make authorized calls.

Even if your script does not have an accessible URL you need to specify one when registering your application where the spotify authentication API will redirect to after successful login. The URL doesn't need to work or be accessible, you can specify "http://localhost/", after successful login you just need to copy the "http://localhost/?code=..." URL from your browser and paste it to the console where your application is running. For example:

In order to help other developers to get used to rspotify, I registerd a Spotify account with temporary email. Your guys could test rspotify with this account's CLIENT_ID and CLIENT_SECRET, check .env file for more details.


If you have a use case you are interested in, you could check the examples, which has all kinds of detailed examples. For example, If you want to get recently played history, you could check current_user_recently_played. This is the example code:

rspotify = { version = "0.9"}
tokio = { version = "0.2", features = ["full"] }
extern crate rspotify;

use rspotify::client::Spotify;
use rspotify::oauth2::SpotifyClientCredentials;
use rspotify::senum::Country;

async fn main() {
    // Set client_id and client_secret in .env file or
    // export CLIENT_ID="your client_id"
    // export CLIENT_SECRET="secret"
    let client_credential = SpotifyClientCredentials::default().build();

    // Or set client_id and client_secret explictly
    // let client_credential = SpotifyClientCredentials::default()
    //     .client_id("this-is-my-client-id")
    //     .client_secret("this-is-my-client-secret")
    //     .build();
    let spotify = Spotify::default()
    let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP";
    let tracks = spotify
        .artist_top_tracks(birdy_uri, Country::UnitedStates)
    println!("{:?}", tracks.unwrap());

Blocking API example

There is an optional "blocking" client API that can be enabled:

rspotify = { version = "0.9", features=["blocking"]}
extern crate rspotify;

use rspotify::blocking::client::Spotify;
use rspotify::blocking::oauth2::SpotifyClientCredentials;
use rspotify::senum::Country;

fn main() {
    let client_credential = SpotifyClientCredentials::default().build();
    let spotify = Spotify::default()
    let birdy_uri = "spotify:artist:2WX2uTcsvV5OnS0inACecP";
    let tracks = spotify.artist_top_tracks(birdy_uri, Country::UnitedStates);
    println!("{:?}", tracks.unwrap());


API Documentation

For more API information, you could check rspotify Api documentation


Please see the CHANGELOG for a release history.


If you find any problem or have suggestions about this crate, please submit an issue. Moreover, any pull request ,code review and feedback are welcome.




~196K SLoC