Server-backed sessions for Sanic with Redis, Memcache, and MongoDB support
Project description
Sanic session management
sanic_sessions is session management extension for Sanic that integrates server-backed sessions with most convenient API.
sanic_sessions 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_sessions
Example
A simple example uses the in-memory session interface.
from sanic import Sanic
from sanic.response import text
from sanic_sessions import Session, InMemorySessionInterface
app = Sanic(name="ExampleApp")
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(str(request.ctx.session["foo"]))
if __name__ == "__main__":
app.run(host="0.0.0.0", port=8000)
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_sessions-0.1.0.tar.gz.
File metadata
- Download URL: sanic_sessions-0.1.0.tar.gz
- Upload date:
- Size: 11.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0eaee221889e0c635196f591457073826839be6589d035080c4bf62171d339e2
|
|
| MD5 |
93695c61c4c9d563eae2d3ba43ffe768
|
|
| BLAKE2b-256 |
1a800250f998d678fe4112317ecef6b5d5d622e2ad627c0d431716322f1f14e0
|
File details
Details for the file sanic_sessions-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sanic_sessions-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a0dc8cbf59ed74b576f74820d9827dc024e8fac92e66aad8e4ed29744eae60c3
|
|
| MD5 |
676110eb8da81c784ca13763f23f86f4
|
|
| BLAKE2b-256 |
4eb0f7df91fd381f887f55f80ad4e2c0ed8bb32d2764cbb6cd1812265b732bd2
|