Skip to main content

blackbull-session

Signed-cookie sessions for BlackBull, a native Python web framework.

⚠ Early Alpha — API may break between MINOR versions.

PyPI Python License

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

Version 0.2.0 requires BlackBull 0.70.0 or later.

pip install blackbull-session

Use

from blackbull import BlackBull
from blackbull_session import SessionExtension

app = BlackBull()
SessionExtension(app)  # reads BB_SESSION_SECRET


@app.route(path="/")
async def index(conn):
    session = conn.state["session"]
    session["hits"] = session.get("hits", 0) + 1
    return f"Visits: {session['hits']}"

Save the example as example.py, set BB_SESSION_SECRET, and start it with blackbull example:app --bind 127.0.0.1:8000. Use HTTPS to exercise the default Secure cookie. For loopback HTTP development, pass secure=False to SessionExtension.

For deferred initialization, create session = SessionExtension() and call session.init_app(app) in place of SessionExtension(app). The extension is then available at app.extensions["session"].

Upgrade from 0.1.0a1

In native handlers, replace scope["session"] with conn.state["session"], as shown above.

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

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

Source distribution (sdist)

Source distribution for blackbull-session 0.2.0
File Size Uploaded Provenance Actions
blackbull_session-0.2.0.tar.gz 17.0 kB With provenance Details for blackbull_session-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for blackbull-session 0.2.0
File Interpreter ABI Platform Actions
blackbull_session-0.2.0-py3-none-any.whl Python 3 none any Details for blackbull_session-0.2.0-py3-none-any.whl

Total release size: 30.0 kB

Release files / blackbull_session-0.2.0.tar.gz

Download URL blackbull_session-0.2.0.tar.gz
Size 17.0 kB
Tags Source
SHA-256 checksum
How to use checksums
40f35ad351401626f84dd204fd9898fb906e41d6ab8023959e8298f055ac61ae
BLAKE2b-256 checksum
How to use checksums
016d0b2708013e666ac73762a5d90ccd8b7169d920648d8b0a4c9880a0ac47b6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Release files / blackbull_session-0.2.0-py3-none-any.whl

Download URL blackbull_session-0.2.0-py3-none-any.whl
Size 13.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3f56f0b5ac1f9a41e2121e4996283efd5b45cbbf27243acd1ca75fa2969cd4c6
BLAKE2b-256 checksum
How to use checksums
3ea4dc26fc14b449f7f195f34bec2607b773fb20a8c218ab6f446d4053d1bc4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.13

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

Security for blackbull-session 0.2.0

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.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for blackbull_session-0.2.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 28, 2026.

Transparency log

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.

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