Skip to main content

spotify.py is an asynchronous API wrapper for Spotify written in Python.

Project description

logo

Version info GitHub stars Discord

spotify.py

An API library for the spotify client and the Spotify Web API written in Python.

Spotify.py is an, primarily, asyncronous library (everything down to the HTTP client is asyncio friendly).

Sync' support

The library also supports syncronous usage with spotify.sync

import spotify.sync as spotify  # Nothing requires async/await now!

example

  • Sorting a playlist by popularity
import sys

import spotify

playlist_uri =   # Playlist uri here
client_id =      # App client id here
secret =         # App secret here
token =          # User token here

client = spotify.Client(client_id, secret)

async def main():
    user = await spotify.User.from_token(client, token)

    try:
        playlist = next(playlist for playlist in (await user.get_playlists()) if playlist.uri == playlist_uri)
    except StopIteration:
        print('No playlists were found!', file=sys.stderr)
        return
    else:
        tracks = await playlist.get_all_tracks()

    sorted_tracks = sorted(tracks, reverse=True, key=(lambda track: track.popularity))

    await user.replace_tracks(playlist, sorted_tracks)

if __name__ == '__main__':
    client.loop.run_until_complete(main())

Installing

To install the library simply clone it and run setup.py

  • git clone https://github.com/mental32/spotify.py
  • python3 setup.py install

or use pypi

  • pip3 install spotify (latest stable)
  • pip3 install -U git+https://github.com/mental32/spotify.py (nightly)

Resources

For resources look at the examples or ask in the discord

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

spotify-0.5.1.tar.gz (31.4 kB view details)

Uploaded Source

File details

Details for the file spotify-0.5.1.tar.gz.

File metadata

  • Download URL: spotify-0.5.1.tar.gz
  • Upload date:
  • Size: 31.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.1 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.4

File hashes

Hashes for spotify-0.5.1.tar.gz
Algorithm Hash digest
SHA256 d386a0ddf4b3ce2436d015cd9de5fa36a1c73d6bca77a9ea2122fe265ac7f807
MD5 9c9634968d2a7f03a7fdf0090ff3af91
BLAKE2b-256 9de81b541c72560c5cc2d22f1c16fdb17b824a03f2e1db5030c8031426b3c6da

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page