sessions for aiohttp.web
Project description
# aiohttp_session
The library provides sessions for aiohttp.web.
Usage
The library allows to store user-specific data into session object.
The session object has dict-like interface (operations like session[key] = value, value = session[key] etc. are present).
Before processing session in web-handler you have to register session middleware in aiohttp.web.Application.
A trivial usage example:
import asycio import time from aiohttp import web import aiohttp_session @asyncio.coroutine def handler(request): session = aiohttp_session.get_session(request) session['last_visit'] = time.time() return web.Response('OK') app = web.Application(middlewares=aiohttp_session.session_middleware( aiohttp_session.EncryptedCookieStorage(b'Sixteen byte key'))) app.router.add_route('GET', '/', handler)
All storages uses HTTP Cookie named AIOHTTP_COOKIE_SESSION for storing data.
Available session storages are:
aiohttp_session.SimpleCookieStorage() – keeps session data as plain JSON string in cookie body. Use the storage only for testing purposes, it’s very non-secure.
aiohttp_session.cookie_storage.EncryptedCookieStorage(secret_key) – stores session data into cookies as SimpleCookieStorage but encodes it via AES cipher. secrect_key is a bytes key for AES encryption/decryption, the length should be 16 bytes.
Requires PyCrypto library:
$ pip install aiohttp_session[pycrypto]
aiohttp_session.redis_storage.RedisStorage(redis_pool) – stores JSON-ed data into redis, keepeng into cookie only redis key (random UUID). redis_pool is aioredis pool object, created by yield from aioredis.create_pool(...) call.
Requires aioredis library:
$ pip install aiohttp_session[aioredis]
License
aiohttp_session is offered under the Apache 2 license.
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 aiohttp_session-0.0.1.tar.gz
.
File metadata
- Download URL: aiohttp_session-0.0.1.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2e78ba35c4e49791afab2a84eb6483cff357ddb5f7150d292d082623f1d70cdb |
|
MD5 | 34c9bcc64fc185759be713a397632e7f |
|
BLAKE2b-256 | 09a2bd2b809fdd04f25447c747f014ffe94b6cdf361a3ff74490daef40b776f8 |
Provenance
File details
Details for the file aiohttp_session-0.0.1-py3-none-any.whl
.
File metadata
- Download URL: aiohttp_session-0.0.1-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef125ce5dd59185a2746a65c43577a9995948a189a8cf64f5a06dd0b29de989f |
|
MD5 | f2f65ffa61024d9b710eb4be16f3052b |
|
BLAKE2b-256 | bc6390513c9ec086fa69519df16638a49dc7150c88b7a6c0254dacd765b1718f |