Starlette Session Middleware ·

Purpose
The purpose of this project is to provide an enhanced, more flexible ASGI session middleware
Getting started
In the project root, you will want to create and activate a Python virtual environment in a folder called .venv.
On Fedora 38 this can be done by running python3.9 -m venv .venv && source .venv/bin/activate. You will then want to
pip install all of the dependencies for local development. This can be done by running pip install -r requirements.txt
in your Python 3.9 virtual environment. After that, you will want to run pre-commit install to install all of the
pre-commit hooks. This ensures that we reduce unneeded pipeline failures.
Running the Tests
You can run the tests by running python -m pytest -n auto --cov. This will use pytest-xdist to parallelize the tests and provide a code
coverage report by using pytest-cov.
Usage
FastAPI
In order to use a JWT persisted with a cookie and passed through a cookie, you would create the middleware as follows.
from fastapi import FastAPI
from starlette_session.middleware import SessionMiddleware
from starlette_session.middleware.codecbackends.jwt import JwtCodecBackend
from starlette_session.middleware.storagebackends.cookie import CookieStorageBackend
from starlette_session.middleware.authorizationbackends.cookie import CookieAuthorizationBackend
app = FastAPI()
app.add_middleware(
SessionMiddleware,
codec_backend=JwtCodecBackend(key="somesuperdupersecurekey")
storage_backend=CookieStorageBackend()
authorization_backend=CookieAuthorizationBackend()
)
In order to use a JWT persisted with a cookie and passed through the Authorization header, you would create the middleware as follows.
from fastapi import FastAPI
from starlette_session.middleware import SessionMiddleware
from starlette_session.middleware.codecbackends.jwt import JwtCodecBackend
from starlette_session.middleware.storagebackends.cookie import CookieStorageBackend
from starlette_session.middleware.authorizationbackends.authorizationheader import AuthorizationHeaderAuthorizationBackend
app = FastAPI()
app.add_middleware(
SessionMiddleware,
codec_backend=JwtCodecBackend(key="somesuperdupersecurekey")
storage_backend=CookieStorageBackend()
authorization_backend=AuthorizationHeaderAuthorizationBackend()
)
Release files for starlette-session-middleware 0.1.6
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| starlette_session_middleware-0.1.6.tar.gz | 8.6 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| starlette_session_middleware-0.1.6-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.6 kB
Release files / starlette_session_middleware-0.1.6.tar.gz
| Download URL | starlette_session_middleware-0.1.6.tar.gz |
|---|---|
| Size | 8.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8cc5c14da6e1bd3a5de158b038a5cb13f3a1c1291a9415d961578ba3d5c6ba93
|
|
BLAKE2b-256 checksum How to use checksums |
6e25f5f8bf823af9f1bbdceedf55ecccc2021057cf3f532aaa04e8c024a42f6e
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jan 5, 2026.
Transparency logRelease files / starlette_session_middleware-0.1.6-py3-none-any.whl
| Download URL | starlette_session_middleware-0.1.6-py3-none-any.whl |
|---|---|
| Size | 11.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e8315901cb5ea79a3195767247a934bf98a931a360c8559a9dd74014db7ba0e9
|
|
BLAKE2b-256 checksum How to use checksums |
37592da284ad68fffa161f36db49fdb70414a6acd7a2c63b3c053bff2dd7fbbb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
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 Jan 5, 2026.
Transparency log