Skip to main content
Gotta get your sessions fast!
=============================

Cookie-based sessions are still a common way to track users's sessions.
Flask and Django have really good support for server-side sessions, but not Sanic yet.
So `sanic-secure-session` is an attempt to create a simple yet enough secure session support for Sanic.

* Server-side sessions (currently only Redis backend implemented)
* Signed session cookie (sure, using `itsdangerous`)
* Easily extensible backends (only serialization and storage-related logic there)

## Usage example


```python
from datetime import timedelta

import asyncio_redis
from sanic import Sanic
from sanic.response import text

from sanic_secure_session import SanicSession
from sanic_secure_session.backends.redis import RedisStorageBackend


class RedisPool:
"""
A simple wrapper class that allows you to share a connection
pool across your application.
"""
_pool = None

async def get_pool(self):
if not self._pool:
self._pool = await asyncio_redis.Pool.create(
host='localhost', port=6379, poolsize=10
)

return self._pool


redis_pool = RedisPool()

storage_backend = RedisStorageBackend(redis_connection=redis_pool.get_pool)

app = Sanic()
SanicSession(app, secret_key='aeNgaif6Ieyishoh', storage_backend=storage_backend,
ttl=timedelta(minutes=1), http_only=True, secure=True)


@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({
'cookies': request.cookies,
'session': request['session']
})


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

```




Release files for sanic-secure-session 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sanic-secure-session 0.2.1
File Size Uploaded
sanic-secure-session-0.2.1.tar.gz 4.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sanic-secure-session 0.2.1
File Interpreter ABI Platform
sanic_secure_session-0.2.1-py2.py3-none-any.whl Python 2, Python 3 none any Details

Total release size: 9.5 kB

Release files / sanic-secure-session-0.2.1.tar.gz

Download URL sanic-secure-session-0.2.1.tar.gz
Size 4.0 kB
Tags Source
SHA-256 checksum
How to use checksums
be8ffe8ded402dd55d71e1cae9fca9ac168e60087294de4b37e85f065d0d2dc6
BLAKE2b-256 checksum
How to use checksums
a6dcc6a79f86988bc1df3e98e7f51c7e3fa26d2d025d98cd30444f49df00adf5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / sanic_secure_session-0.2.1-py2.py3-none-any.whl

Download URL sanic_secure_session-0.2.1-py2.py3-none-any.whl
Size 5.5 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
73e7ae180b25f833f2d32ad98386e73621b89717bb4fd6d1cd52cae4ab2b0bf3
BLAKE2b-256 checksum
How to use checksums
b00f129ea1c208ace2d1bfac1e1560743354ddc344c25602b09a4ef738d37a26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page