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
andasyncio_redis
) - Memcache (via
aiomcache
) - Mongodb (via
sanic_motor
andpymongo
) - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file sanic_session-0.5.1.tar.gz
.
File metadata
- Download URL: sanic_session-0.5.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4c1432851759d771e234d1d100dfe4ff932039fb590c9e9d21e0b5385c7a2e95 |
|
MD5 | b1f97fc0fd585e0bf32e856d2ff04739 |
|
BLAKE2b-256 | 8b8dcffd143c9cf62dc144b7774aff0db494affc6d08a6d708df23e7b09cbcdc |
File details
Details for the file sanic_session-0.5.1-py3-none-any.whl
.
File metadata
- Download URL: sanic_session-0.5.1-py3-none-any.whl
- Upload date:
- Size: 12.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.7.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f0f9e1f9b1f0cf1e7409c7f23d4b89c9721f972488d3bfbd6291520bf7f08f4a |
|
MD5 | f5ce5b430c8bf45a328d2682b1626a1f |
|
BLAKE2b-256 | fff61b33bf5827f7eb0172f65a7fe8eef7f92bd05eeb166e899037f12a5bfe22 |