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

Metadata

Release files for bareASGI-session 4.0.0a3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bareASGI-session 4.0.0a3
File Size Uploaded
bareASGI-session-4.0.0a3.tar.gz 8.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bareASGI-session 4.0.0a3
File Interpreter ABI Platform
bareASGI_session-4.0.0a3-py3-none-any.whl Python 3 none any Details

Total release size: 19.2 kB

Release files / bareASGI-session-4.0.0a3.tar.gz

Download URL bareASGI-session-4.0.0a3.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
9e826b7346fb765f8383efd0b63e6b8b2dabf40b6f12b5a21b298d2e17e3ae50
BLAKE2b-256 checksum
How to use checksums
a0f0549def270f9d60e33da692e8b9c44007978a16c27be32c194a830c6df6f6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.8.10 Linux/5.4.0-84-generic

Release files / bareASGI_session-4.0.0a3-py3-none-any.whl

Download URL bareASGI_session-4.0.0a3-py3-none-any.whl
Size 10.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e72d9dd82ae87f122dd74c074efe87daef7f92a8f1ccec2573618312b425faee
BLAKE2b-256 checksum
How to use checksums
72b1b846a8d6ee7789bc7ac29b5cb84d1b076de266ea0f425420aafe1bc3d64b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.8 CPython/3.8.10 Linux/5.4.0-84-generic
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