Provides server-backed sessions for Sanic using Redis, Memcache and more.
Project description
Sanic session management for humans
:warning: Warning: This poject in Pull-Request-Only mode. I don't use Sanic anymore for any of my projects and will not make any changes by my own in foreseeable future. I recommend to use AIOHTTP since it more mature and have bigger adoption (I'm not judging by github stars only). Though I will accept pull requests from others if you want to see updates in the code.
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
aioredisandasyncio_redis) - Memcache (via
aiomcache) - Mongodb (via
sanic_motorandpymongo) - 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
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sanic_session-0.8.0.tar.gz.
File metadata
- Download URL: sanic_session-0.8.0.tar.gz
- Upload date:
- Size: 9.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9c500f015f22577d5c9c7743d637741b50f97e1689fa795318d614b6dbb58d8
|
|
| MD5 |
b2c0e0aaa8737b120811dc7457584b15
|
|
| BLAKE2b-256 |
da9914e37b8a0141495d5141adbc62bb88c223a6fd53255b8ab623d20dc89c09
|
File details
Details for the file sanic_session-0.8.0-py3-none-any.whl.
File metadata
- Download URL: sanic_session-0.8.0-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/3.10.0 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ead1b62c4c7773cfaaa22d77ed0eb23b423d1d60b21e11225cc9132dff37b2dd
|
|
| MD5 |
f9f074db3a97e382afc729db89784c25
|
|
| BLAKE2b-256 |
233af9df6b7206956b150ca9057659fc85ded4ee607c531e4f29fe5c65cb3f61
|