Skip to main content

Provides server-backed sessions for Sanic using Redis, Memcache and more.

Project description

Sanic session management for humans

Build Status ReadTheDocs License: MIT PyPI version Black

sanic_session is session management extension for Sanic that integrates server-backed sessions with most convenient API.

sanic_session provides a number of session interfaces for you to store a client's session data. The interfaces available right now are:

  • Redis (supports both drivers aioredis and asyncio_redis)
  • Memcache (via aiomcache)
  • Mongodb (via sanic_motor and pymongo)
  • In-Memory (suitable for testing and development environments)

Installation

Install with pip (there is other options for different drivers, check documentation):

pip install sanic_session

or if you prefer Pipenv:

pipenv install sanic_session

Documentation

Documentation is available at sanic-session.readthedocs.io.

Also, make sure you read OWASP's Session Management Cheat Sheet for some really useful info on session management.

Example

A simple example uses the in-memory session interface.

from sanic import Sanic
from sanic.response import text
from sanic_session import Session, InMemorySessionInterface

app = Sanic()
session = Session(app, interface=InMemorySessionInterface())

@app.route("/")
async def index(request):
    # interact with the session like a normal dict
    if not request.ctx.session.get('foo'):
        request.ctx.session['foo'] = 0

    request.ctx.session['foo'] += 1

    return text(request.ctx.session['foo'])

if __name__ == "__main__":
    app.run(host="0.0.0.0", port=8000)

Examples of using redis and memcache backed sessions can be found in the documentation, under Using the Interfaces.

— ⭐️ —

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

sanic_session-0.7.3.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

sanic_session-0.7.3-py3-none-any.whl (13.0 kB view details)

Uploaded Python 3

File details

Details for the file sanic_session-0.7.3.tar.gz.

File metadata

  • Download URL: sanic_session-0.7.3.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.8.0 tqdm/4.39.0 CPython/3.8.0

File hashes

Hashes for sanic_session-0.7.3.tar.gz
Algorithm Hash digest
SHA256 ede029e122ddfa0734c77207ed27264d13697aae0ab45309702c3162a10cf824
MD5 111811efdf1ba321da84f03dc43eb83c
BLAKE2b-256 2e963ad96251cf24f62325c7869db4de3160bdbea8dd9e94c21df55efee0a008

See more details on using hashes here.

File details

Details for the file sanic_session-0.7.3-py3-none-any.whl.

File metadata

  • Download URL: sanic_session-0.7.3-py3-none-any.whl
  • Upload date:
  • Size: 13.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.6.0 requests-toolbelt/0.8.0 tqdm/4.39.0 CPython/3.8.0

File hashes

Hashes for sanic_session-0.7.3-py3-none-any.whl
Algorithm Hash digest
SHA256 308e27ca0af8fdd3d43ff7303337b73b5da686096dc2bc3258afbdcd6aca11fd
MD5 7c448b7ea547daa52dd6959ff0f1f954
BLAKE2b-256 42ef69424cee6cca510313e9247c1bd01cafb195e87da8e8c2283ee316032ac1

See more details on using hashes here.

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