This release is a pre-release and may not be stable for production use.
blackbull-session
Signed-cookie session extension for the BlackBull ASGI framework.
⚠ Early Alpha — API may break between MINOR versions.
What this is
A session layer for BlackBull apps. The entire session payload lives in the cookie sent to the client; the server keeps no per-session state. Every value the client could otherwise tamper with is HMAC-signed by a secret the server alone knows, so:
- a client that modifies the cookie sees the next request treated as a fresh empty session (signature check fails),
- the server never reads, writes, or replays anything else — no DB hit, no Redis round-trip, no in-process dict to keep consistent across workers,
- sessions survive worker restarts / horizontal scaling for free (any worker that knows the secret can validate any cookie).
The trade-offs compared with server-side session stores:
- Cookie size is bounded (browsers cap to ~4 KiB, often less in practice). Sessions storing large objects don't fit.
- No server-side invalidation: revoking a cookie before it expires requires either rotating the secret (kills every session) or a separate revocation list. Acceptable for many apps; if you need fine-grained revocation, pick a server-side session store instead.
Install
pip install blackbull-session
Use
import os
from blackbull import BlackBull
from blackbull_session import SessionExtension
app = BlackBull()
# Eager — wire on construction.
SessionExtension(app, secret=os.environ['BB_SESSION_SECRET'])
# Or deferred — useful when the app is configured elsewhere.
session = SessionExtension(secret=os.environ['BB_SESSION_SECRET'])
session.init_app(app)
@app.route(path='/')
async def index(scope, receive, send):
user = scope['session'].get('user')
scope['session']['hits'] = scope['session'].get('hits', 0) + 1
await send(...)
After init_app(app), the live extension is reachable at app.extensions['session'].
Configuration
| Parameter | Default | Notes |
|---|---|---|
secret |
reads BB_SESSION_SECRET |
Required. HMAC-SHA256 key (bytes or str). Generate with python -c "import secrets; print(secrets.token_urlsafe(32))". |
cookie_name |
'session' |
Cookie name carrying the payload. |
max_age |
None |
When set (seconds), the cookie is signed with a server-side timestamp; older payloads are treated as expired. None means a session cookie that lives only as long as the browser is open. |
secure |
True |
Secure attribute — cookie sent only over HTTPS. |
httponly |
True |
HttpOnly attribute — JavaScript can't read the cookie. |
samesite |
'Lax' |
Strict / Lax / None (string), or Python None to omit the attribute entirely. |
path |
'/' |
Cookie Path attribute. |
How it fits
blackbull-session is a reference third-party extension that follows the init_app(app) convention — the same convention BlackBull's own in-tree OpenAPIExtension uses. It exists partly to validate that the convention works for external packages without modifications.
License
Apache License 2.0 — © TOKUJI.
Metadata
Release files for blackbull-session 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| blackbull_session-0.1.0a1.tar.gz | 14.5 kB | Without provenance | Details for blackbull_session-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| blackbull_session-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for blackbull_session-0.1.0a1-py3-none-any.whl |
Total release size: 27.0 kB
Release files / blackbull_session-0.1.0a1.tar.gz
| Download URL | blackbull_session-0.1.0a1.tar.gz |
|---|---|
| Size | 14.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5e117986f362597d64524ddbf90f9727c47feb2a773a73ea69d493f30970ad29
|
|
BLAKE2b-256 checksum How to use checksums |
89fc2b14354c24943658a39c36db16a5a54091682efda76ffd257297120de67c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / blackbull_session-0.1.0a1-py3-none-any.whl
| Download URL | blackbull_session-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 12.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0742dc6fdaeae3a6406aba0ff4b13d7e6942715d33bcc8b4e42d0ba1cc0d4329
|
|
BLAKE2b-256 checksum How to use checksums |
2aaa84fecb9a807a59d3ecfdee499d85063e64396330af45709dd95c4478bb65
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Security for blackbull-session 0.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.