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 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


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.2.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

aiohttp_session_file-0.0.2-py3-none-any.whl (3.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiohttp-session-file-0.0.2.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.1

File hashes

Hashes for aiohttp-session-file-0.0.2.tar.gz
Algorithm Hash digest
SHA256 50e7f6b32e3affd89849b24df3cb937e40dc101ed7167875b00817fdcec6f953
MD5 68f6aa59d14e1caefd554ec585004cde
BLAKE2b-256 fe08853ac339e85d65c65b3c0c68c018cc8e5b03582e2f6a6ef252b0aa12e9f9

See more details on using hashes here.

Provenance

File details

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

File metadata

  • Download URL: aiohttp_session_file-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 3.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/42.0.2 requests-toolbelt/0.9.1 tqdm/4.28.1 CPython/3.8.1

File hashes

Hashes for aiohttp_session_file-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 b75fccf4db7c947602aef506759415c0d7921a2cd323b0e66ec4feee91219e7d
MD5 ca3015597e7d2fbc813beaebb57d7f92
BLAKE2b-256 5ac1718171408d8b42b138ddbb7c0f6873920678d945055615dc208adfdda6ca

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