The library provides sessions for aiohttp.web.


The library allows to store user-specific data into session object.

The session object has dict-like interface (operations like session[key] = value or value = session[key] etc. are supported).

Before processing session in web-handler you have to register session middleware in aiohttp.web.Application.

A trivial usage example:

import time
from aiohttp import web
from aiohttp_session import get_session, setup
from aiohttp_session.cookie_storage import EncryptedCookieStorage

async def handler(request):
    session = yield from get_session(request)
    session['last_visit'] = time.time()
    return web.Response(body=b'OK')

def init():
    app = web.Application()
        EncryptedCookieStorage(b'Thirty  two  length  bytes  key.'))
    app.router.add_route('GET', '/', handler)
    return app


All storages uses HTTP Cookie named AIOHTTP_COOKIE_SESSION for storing data.

Available session storages are:


pip3 install aiohttp_session

Source code

The project is hosted on GitHub

Please feel free to file an issue on bug tracker if you have found a bug or have some suggestion for library improvement.

The library uses Travis for Continious Integration.



aiohttp_session is offered under the Apache 2 license.


Indices and tables