Skip to content
Spotify Web API wrapper implemented in Rust
Branch: master
Clone or download
Latest commit 25aa117 Jan 30, 2020
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github/workflows remove continuoue-on-error configuration, stop step on error. Jan 30, 2020
doc/images update README Feb 18, 2018
examples Run rustfmt across codebase Jan 29, 2020
src update rspotify to 0.8 Jan 30, 2020
.env create .env file and update Jan 20, 2020
.gitignore create .env file and update Jan 20, 2020
.travis.yml fix travis again Jan 20, 2020 update rspotify to 0.8 Jan 30, 2020
Cargo.toml update rspotify to 0.8 Jan 30, 2020
LICENSE add CHNAGELOG and LICENSE Feb 19, 2018 Update Jan 30, 2020 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:

extern crate rspotify;

use rspotify::spotify::client::Spotify;
use rspotify::spotify::util::get_token;
use rspotify::spotify::oauth2::{SpotifyClientCredentials, SpotifyOAuth};

fn main() {
    // Set client_id and client_secret in .env file or
    // export CLIENT_ID="your client_id"
    // export CLIENT_SECRET="secret"
    // export REDIRECT_URI=your-direct-uri

    // Or set client_id, client_secret,redirect_uri explictly
    // let oauth = SpotifyOAuth::default()
    //     .client_id("this-is-my-client-id")
    //     .client_secret("this-is-my-client-secret")
    //     .redirect_uri("http://localhost:8888/callback")
    //     .build();

    let mut oauth = SpotifyOAuth::default()
    match get_token(&mut oauth) {
        Some(token_info) => {
            let client_credential = SpotifyClientCredentials::default()
            // 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 history = spotify.current_user_recently_played(10);
            println!("{:?}", history);
        None => println!("auth failed"),

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.



You can’t perform that action at this time.