Skip to main content

An async Python interface to the Spotify API using aiohttp

Project description

An async Python interface to the Spotify API using aiohttp.

Note: This is alpha software. Use at your own risk.

Installation

To install, use pip:

python -m pip install aiohttp_spotify

It's best if you also install and use aiohttp-session.

Usage

To add the OAuth flow to your app:

from aiohttp import web
import aiohttp_spotify

async def handle_auth(request: web.Request, auth: aiohttp_spotify.SpotifyAuth):
    # Store the `auth` object for use later

app = web.Application()
app["spotify_app"] = aiohttp_spotify.spotify_app(
    client_id=CLIENT_ID,
    client_secret=CLIENT_SECRET,
    redirect_uri=REDIRECT_URI,
    handle_auth=handle_auth,
)
app.add_subapp("/spotify", app["spotify_app"])

Then you can make calls to the API as follows:

from aiohttp import ClientSession

async def call_api(request: web.Request) -> web.Response:
    async with ClientSession() as session:
        response = app["spotify_app"]["spotify_client"].request(
            session, auth, "/me"
        )

    # The auth object will be updated as tokens expire so you should
    # update this however you have it stored:
    if response.auth_changed:
        await handle_auth(request, response.auth)

    return web.json_request(response.json())

where auth is the SpotifyAuth object from above.

Take a look at the demo directory for a more complete example.

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

aiohttp_spotify-0.0.3.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

aiohttp_spotify-0.0.3-py2.py3-none-any.whl (8.3 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file aiohttp_spotify-0.0.3.tar.gz.

File metadata

  • Download URL: aiohttp_spotify-0.0.3.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1.post20200323 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for aiohttp_spotify-0.0.3.tar.gz
Algorithm Hash digest
SHA256 ca6077315bd34d3ba30d4fd2637a82ce3962fb76acbdb4568e35a001e46515b5
MD5 e8dd54587f48b57567a4de0698409b97
BLAKE2b-256 19d6afea3ee7383c39c1d54a5bdc063505f213b20623c59e245e6f245c496f11

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp_spotify-0.0.3-py2.py3-none-any.whl.

File metadata

  • Download URL: aiohttp_spotify-0.0.3-py2.py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.1.post20200323 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.1

File hashes

Hashes for aiohttp_spotify-0.0.3-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 42b3a7ce03085b2b168e465621f2a591f91ef71f62ebc3291c20b3bb6c1e9c6b
MD5 efbdffdd48463d82418b07c99920e9c5
BLAKE2b-256 ea900ea894aa1f09ded07cb1e9eb96bd7a1feb6f9bfb94142486f4495241c0bf

See more details on using hashes here.

Provenance

Supported by

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