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 tempfile
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()
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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 594704748db93786de0b9c2355c03e6eb151f2f9c97352d89f3bb3e85c23dc13 |
|
MD5 | 62a7100fedf79d5e3260bc57a63094fd |
|
BLAKE2b-256 | c8bf44fcf7bf62cefae3fb14c31ec22ea008f1ad6c8afab6b6bb830923d3f43e |
Close
Hashes for aiohttp_session_file-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8eb7fe106d52413483bf39c4807a73b7f8b8f7644e9b623254ea7220b0ccefc5 |
|
MD5 | cbb0a2914b6b7831b3ff8774e112a8c5 |
|
BLAKE2b-256 | 8002e307c81219ded1fd818eeded62c7d9db8957e1883c2aed4b47f35e946a90 |