


[](https://deepsource.io/gh/kokarare1212/librespot-python/?ref=repository-badge)

# Librespot-Python
Open Source Spotify Client
## Support Project
If you find our project useful and want to support its development, please consider making a donation. Your contribution will help us maintain and improve the project, ensuring that it remains free and accessible to everyone.
[](https://github.com/sponsors/kokarare1212)
[](https://liberapay.com/kokarare1212/)
## About The Project
This project was developed to make the music streaming service Spotify available
on any device.
## Attention!
This repository has been completely rewritten from the transplant.
There may be some functions that are not implemented yet.
If so, please feel free to open an issue.
## Note
It is still in the idea stage, so there is a possibility of unintended behavior
or major specification changes.
We **DO NOT** encourage piracy and **DO NOT** support any form of downloader/recorder designed with the help of this repository and in general anything that goes against the Spotify ToS.
For other guidelines, please see [CODE_OF_CONDUCT.md](https://github.com/kokarare1212/librespot-python/blob/main/CODE_OF_CONDUCT.md).
## Getting Started
### Prerequisites
- [Python](https://python.org/)
### Installation
Stable Version
```commandline
pip install librespot
```
Snapshot Version \***Recommended**
```commandline
pip install git+https://github.com/kokarare1212/librespot-python
```
## Usage
### Use Zeroconf for Login
```python
from librespot.zeroconf import ZeroconfServer
zeroconf = ZeroconfServer.Builder().create()
```
### Use OAuth for Login
#### Without auth url callback
```python
from librespot.core import Session
# This will log an url in the terminal that you have to open
session = Session.Builder() \
.oauth(None) \
.create()
```
#### With auth url callback and changing the content of the success page
```python
from librespot.core import Session
import webbrowser
# This will pass the auth url to the method
def auth_url_callback(url):
webbrowser.open(url)
# This is the response sent to the browser once the flow has been completed successfully
success_page = "
You can close this window now.
" session = Session.Builder() \ .oauth(auth_url_callback, success_page) \ .create() ``` ### Use Stored Credentials for Login ```python from librespot.core import Session # Supports both Python and Rust librespot credential formats session = Session.Builder() \ .stored_file("/path/to/credentials.json") \ .create() ``` ### Get Spotify's OAuth token ```python from librespot.core import Session session = Session.Builder() \ .oauth(None) \ .create() access_token = session.tokens().get("playlist-read") ``` ### Get Music Stream *Currently, music streaming is supported, but it may cause unintended behavior.