Skip to main content

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


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-file-0.0.1.tar.gz (2.9 kB view details)

Uploaded Source

Built Distribution

aiohttp_session_file-0.0.1-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file aiohttp-session-file-0.0.1.tar.gz.

File metadata

  • Download URL: aiohttp-session-file-0.0.1.tar.gz
  • Upload date:
  • Size: 2.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.4

File hashes

Hashes for aiohttp-session-file-0.0.1.tar.gz
Algorithm Hash digest
SHA256 6c1ee06c05dcb59fb8ded82dbfbfb1af1ac018f86c4cf85129548027ec61cf61
MD5 90b8314af1c5cf29d3c2b719335e732e
BLAKE2b-256 cc4cfcf787c583ab3ed2cbd5f8fcc3ac38591ed3b9c6c9ba9190f4fe17c3fddd

See more details on using hashes here.

Provenance

File details

Details for the file aiohttp_session_file-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: aiohttp_session_file-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.15.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.2.0 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.7.4

File hashes

Hashes for aiohttp_session_file-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cb7ce3a1d419361e1498dfd6fccd42e25bd9e0aedd8840aae0b6835d4e65d3d4
MD5 09895b2d45b318163ae6811f0d8c91b6
BLAKE2b-256 7d17d07baa6a0166a057e37ba7f4b4255d20a9e7d19a2d2240e50cf465433d9b

See more details on using hashes here.

Provenance

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