Metadata-Version: 2.1
Name: spotify
Version: 0.6.0
Summary: spotify.py is an asynchronous API wrapper for Spotify written in Python.
Home-page: https://github.com/mental32/spotify.py
Author: mental
License: MIT
Description: ![logo](/docs/source/images/logo.png)
        
        
        ![Version info](https://img.shields.io/pypi/v/spotify.svg)
        [![GitHub stars](https://img.shields.io/github/stars/mental32/spotify.py.svg)](https://github.com/mental32/spotify.py/stargazers)
        ![Discord](https://img.shields.io/discord/438465139197607939.svg?style=flat-square)
        
        # spotify.py
        
        An API library for the spotify client and the Spotify Web API written in Python.
        
        Spotify.py is an asyncronous API library for Spotify. While maintaining an
        emphasis on being purely asyncronous the library provides syncronous
        functionality with the `spotify.sync` module.
        
        ```python
        import spotify.sync as spotify  # Nothing requires async/await now!
        ```
        
        ## Index
        
         - [Installing](#Installing)
         - [Examples](#Examples)
         - [Resources](#Resources)
        
        ## 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)
        
        ## Examples
        ### Sorting a playlist by popularity
        
        ```py
        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)
        
            playlists = filter((lambda playlist: playlist.uri == playlist_uri), await user.get_playlists())
        
            try:
                playlist = next(playlists)
            except StopIteration:
                print('No playlists were found!', file=sys.stderr)
                return
            else:
                await playlist.sort(reverse=True, key=(lambda track: track.popularity))
        
        if __name__ == '__main__':
            client.loop.run_until_complete(main())
        ```
        
        ### Usage with flask
        
        ```py
        import flask
        import spotify.sync as spotify
        
        SPOTIFY_CLIENT = spotify.Client.from_envvar('SPOTIFY_CLIENT_ID', 'SPOTIFY_CLIENT_SECRET')
        
        APP = flask.Flask(__name__)
        APP.config.from_mapping({'spotify_client': SPOTIFY_CLIENT})
        
        REDIRECT_URI: str = 'http://localhost:8888/spotify/callback'
        OAUTH2: spotify.OAuth2 = spotify.OAuth2(SPOTIFY_CLIENT.id, REDIRECT_URI, scope='user-modify-playback-state,user-read-currently-playing,user-read-playback-state')
        
        
        @APP.route('/spotify/callback')
        def spotify_callback():
            try:
                code = flask.request.args['code']
            except KeyError:
                return flask.redirect('/spotify/failed')
            else:
                flask.session['spotify_user'] = spotify.User.from_code(
                    SPOTIFY_CLIENT,
                    code,
                    redirect_uri=REDIRECT_URI,
                    refresh=True
                )
        
            return flask.redirect('/')
        
        @APP.route('spotify/failed')
        def spotify_failed():
            flask.session.pop('spotify_user', None)
            return 'Failed to authenticate with Spotify.'
        
        @APP.route('/')
        @APP.route('/index')
        def index():
            try:
                return repr(flask.session['spotify_user'])
            except KeyError:
                return flask.redirect(OAUTH2.url)
        
        if __name__ == '__main__':
            APP.run('127.0.0.1', port=8888, debug=False)
        ```
        
        ## Resources
        
        For resources look at the [examples](https://github.com/mental32/spotify.py/tree/master/examples) or ask in the [discord](https://discord.gg/k43FSFF)
        
Platform: UNKNOWN
Classifier: License :: OSI Approved :: MIT License
Classifier: Intended Audience :: Developers
Classifier: Natural Language :: English
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Topic :: Internet
Classifier: Topic :: Software Development :: Libraries
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: Utilities
Requires-Python: >=3.6
Description-Content-Type: text/markdown
