Skip to main content

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

Project description

Sanic session management for humans

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['session'].get('foo'):
        request['session']['foo'] = 0

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

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

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

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.5.4.tar.gz (8.6 kB view details)

Uploaded Source

Built Distribution

sanic_session-0.5.4-py3-none-any.whl (12.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: sanic_session-0.5.4.tar.gz
  • Upload date:
  • Size: 8.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for sanic_session-0.5.4.tar.gz
Algorithm Hash digest
SHA256 3a2a2bec666e6ab219cc670c21568d3f6abecc635d02c6e5c38e94d5aafcf612
MD5 86ff030a73b6033bf93af8490272bbef
BLAKE2b-256 c5bf53bc5b198eeaf4ed984c5bb2e90ebc2240e374a7cfb1afd29d8d9c436f84

See more details on using hashes here.

File details

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

File metadata

  • Download URL: sanic_session-0.5.4-py3-none-any.whl
  • Upload date:
  • Size: 12.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/41.0.0 requests-toolbelt/0.8.0 tqdm/4.31.1 CPython/3.7.2

File hashes

Hashes for sanic_session-0.5.4-py3-none-any.whl
Algorithm Hash digest
SHA256 c2913fbed6cc9e86eee737fe46978079ab0c0986b3888229cf2a019e377e163e
MD5 8997261dabb3bc6ec4e141962444fe70
BLAKE2b-256 a799ecc6a5837c03dc6fd0042337b50ece3badab18228f6c585a5c67dc64b626

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