No project description provided
Project description
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()
)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for starlette_session_middleware-0.1.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4890eee212da7c6f6d5f6f6a01579281919fe0b89bfa3bcbc1a9f27b610735c7 |
|
MD5 | fd45c978406f647811e2f0e2050a7b53 |
|
BLAKE2b-256 | 5c0c744e02822fc800e1664781fc99832f1abd55c4a9bffe3a6c0ed7e2d3ba89 |
Hashes for starlette_session_middleware-0.1.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c398909e66b4f19cd17c5e023aae5b59f9fefbcc3a8ac038ce29ecacc3b10e9 |
|
MD5 | a1b40ac996f0239ab100c31e9c6627d5 |
|
BLAKE2b-256 | b33339af1d2afc7c7664bf7e41523fa0fe5f79c31f15876fa0e4c7ab538c683d |