Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

bareASGI-session

Session support for bareASGI (read the docs).

Overview

When a client (e.g. a browser tab) makes HTTP requests to a server, the server does not know if the requests came from the same client. This makes it difficult to maintain state information (e.g. the users identity).

A solution which is transparent to the client involves the server sending a cookie to the client. Once the cookie is sent the client will automatically add the cookie to any subsequent request it makes to the server (assuming cookies are enabled). By checking the cookie the server can know which client has sent the request.

Usage

You can add session middleware with the add_session_middleware helper function.

from bareasgi import Application
from bareasgi_session import (
  add_session_middleware,
  MemorySessionStorage
)

app = Application()

add_session_middleware(app, MemorySessionStorage())

The session can be retrieved with the session_data helper function. This returns an (initially empty) dictionary.

from datetime import datetime
from bareutils import text_writer
from bareasgi_session import session_data

async def session_handler(request: HttpRequest) -> HttpResponse:
    session = session_data(request)
    now = session.get('now')
    message = f'The time was {now}' if now else 'First time'
    session['now'] = datetime.now()
    headers: List[Header] = [
        (b'content-type', b'text/plain'),
        (b'content-length', str(len(message)).encode('ascii'))
    ]
    return HttpResponse(200, headers, text_writer(message))

Download files

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

Source Distribution

bareASGI-session-4.0.0a1.tar.gz (8.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

bareASGI_session-4.0.0a1-py3-none-any.whl (9.6 kB view details)

Uploaded Python 3

File details

Details for the file bareASGI-session-4.0.0a1.tar.gz.

File metadata

  • Download URL: bareASGI-session-4.0.0a1.tar.gz
  • Upload date:
  • Size: 8.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.8 CPython/3.9.6 Darwin/19.6.0

File hashes

Hashes for bareASGI-session-4.0.0a1.tar.gz
Algorithm Hash digest
SHA256 be245e6d1173419dadac0c01b8c9ace0ab86a0616d1520ca78be8b8f910da202
MD5 d3a7140a3b50f8096247dc1fee2a9a95
BLAKE2b-256 cdc94133efd5477e59987a9406e7a7f90f5c86d566282d328fddb204993f55a6

See more details on using hashes here.

File details

Details for the file bareASGI_session-4.0.0a1-py3-none-any.whl.

File metadata

File hashes

Hashes for bareASGI_session-4.0.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 38748065fba3aa664e8720ba5229d3ea1e88778bc65d494787c5d5cd960cf8b3
MD5 46f18727db455b2c4f608d3c45c464a6
BLAKE2b-256 c54f2aadd5f21dc9e25384d292b8546d83539f13e16122e246d5bb5b7ec3fcd0

See more details on using hashes here.

Release history Release notifications | RSS feed

5.0.0

2 files

4.0.1

2 files

4.0.0

2 files

This release

4.0.0a1 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page