Skip to main content

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 = yield from 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.

Changes

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiohttp_session-0.1.1.tar.gz (4.6 kB view details)

Uploaded Source

Built Distribution

aiohttp_session-0.1.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp_session-0.1.1.tar.gz.

File metadata

File hashes

Hashes for aiohttp_session-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6390a9c796b2e4b6a7f2c85c3341cc2ec31608d48b7cbdc8b6777b3380a8d6d5
MD5 ebd0d3607db1d89e7a5801c54d820b15
BLAKE2b-256 bcde4d16c8e469d34c023e7608601a58f15f1dc6aa6b3dcf5b3da65b9fe9a5bd

See more details on using hashes here.

File details

Details for the file aiohttp_session-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiohttp_session-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b9d7edc77d46cfa50fa08663bdabcccbe4a7fb13b792287217e94a9820750868
MD5 67bdf3fd0b73f59ef119e6acf156d77d
BLAKE2b-256 b5c7cae15b6bd6f4faa922285cc78d5edad30eae7342b861dd1296db7c82b157

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page