file sessions for aiohttp.web
Project description
The library provides file sessions store for aiohttp.web.
Usage
A trivial usage example:
import asyncio
import shutil
import time
from aiohttp import web
from aiohttp_session import setup, get_session
from aiohttp_session_file import FileStorage
async def handler(request):
session = await get_session(request)
last_visit = session['last_visit'] if 'last_visit' in session else None
session['last_visit'] = time.time()
text = 'Last visited: {}'.format(last_visit)
return web.Response(text=text)
async def setup_dir(app):
dirpath = tempfile.mkdtemp(prefix='aiohttp-session-')
async def remove_dir(app):
shutil.rmtree(dirpath)
app.on_cleanup.append(remove_dir)
return dirpath
async def make_app():
app = web.Application()
loop = asyncio.get_event_loop()
dirpath = await setup_dir(app)
max_age = 3600 * 24 * 365 # 1 year
setup(app, FileStorage(dirpath, max_age=max_age))
app.router.add_get('/', handler)
return app
web.run_app(make_app())
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
Close
Hashes for aiohttp-session-file-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c1ee06c05dcb59fb8ded82dbfbfb1af1ac018f86c4cf85129548027ec61cf61 |
|
MD5 | 90b8314af1c5cf29d3c2b719335e732e |
|
BLAKE2b-256 | cc4cfcf787c583ab3ed2cbd5f8fcc3ac38591ed3b9c6c9ba9190f4fe17c3fddd |
Close
Hashes for aiohttp_session_file-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | cb7ce3a1d419361e1498dfd6fccd42e25bd9e0aedd8840aae0b6835d4e65d3d4 |
|
MD5 | 09895b2d45b318163ae6811f0d8c91b6 |
|
BLAKE2b-256 | 7d17d07baa6a0166a057e37ba7f4b4255d20a9e7d19a2d2240e50cf465433d9b |