Skip to main content

License Stars Forks DeepSource

Counter

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.

GitHub Sponsor Liberapay receiving

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.

Getting Started

Prerequisites

Installation

Stable Version

pip install librespot

Snapshot Version *Recommended

pip install git+https://github.com/kokarare1212/librespot-python

Usage

Use Zeroconf for Login

from librespot.zeroconf import ZeroconfServer

zeroconf = ZeroconfServer.Builder().create()

Use OAuth for Login

Without auth url callback

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

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 = "<html><body><h1>Login Successful</h1><p>You can close this window now.</p><script>setTimeout(() => {window.close()}, 100);</script></body></html>"

session = Session.Builder() \
    .oauth(auth_url_callback, success_page) \
    .create()

Use Stored Credentials for Login

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

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.

from librespot.core import Session
from librespot.metadata import TrackId
from librespot.audio.decoders import AudioQuality, VorbisOnlyAudioQuality

session = Session.Builder() \
    .oauth(None) \
    .create()

track_id = TrackId.from_uri("spotify:track:xxxxxxxxxxxxxxxxxxxxxx")
stream = session.content_feeder().load(track_id, VorbisOnlyAudioQuality(AudioQuality.VERY_HIGH), False, None)
# stream.input_stream.stream().read() to get one byte of the music stream.

Other uses are examples or read this document for detailed specifications.

Debug

To display the debug information, you need to inject the following code at the top of the code.

import logging


logging.basicConfig(level=logging.DEBUG)

Contributing

Pull requests are welcome.

License

Distributed under the Apache-2.0 License. See LICENSE.txt for more information.

Related Projects

Metadata

Release files for librespot 0.0.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for librespot 0.0.10
File Size Uploaded
librespot-0.0.10.tar.gz 107.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for librespot 0.0.10
File Interpreter ABI Platform
librespot-0.0.10-py3-none-any.whl Python 3 none any Details

Total release size: 247.3 kB

Release files / librespot-0.0.10.tar.gz

Download URL librespot-0.0.10.tar.gz
Size 107.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e79e954dc8e51e641d813814112942717ff3c3888a153569613b6f3d17e032d2
BLAKE2b-256 checksum
How to use checksums
e1a6702c1793d24dc59196826b7ffc5d9e93842efa2e0cb5b70c74866e98bd39
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release files / librespot-0.0.10-py3-none-any.whl

Download URL librespot-0.0.10-py3-none-any.whl
Size 139.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
cb3ee4ac63062c986cd91732e29ba0e66c091bc02badf2861bdc8b7d995f7e38
BLAKE2b-256 checksum
How to use checksums
a68dfb07a7162ddadbb2f9b0368efcbab1ce2d3a8b08746fc7a7c32f20e64689
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.11

Release history Release notifications | RSS feed

This release

0.0.10 This release

2 release files

0.0.9

2 release files

0.0.8

2 release files

0.0.7

2 release files

0.0.6

2 release files

0.0.5

2 release files

0.0.4

2 release files

0.0.3

2 release files

0.0.2

2 release files

0.0.1

2 release files

0.0.0

3 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page