Encrypted session middleware for FastAPI using enciphers
Project description
fastapi-enciphers
Encrypted session middleware for FastAPI using enciphers.
Replaces Starlette's default signed cookie session with a fully encrypted one.
Installation
pip install fastapi-enciphers
Usage
from fastapi import FastAPI, Request
from fastapi_enciphers import EnciphersMiddleware
app = FastAPI()
app.add_middleware(EnciphersMiddleware, step=7, key=42)
@app.get("/login")
async def login(request: Request):
request.session["user_id"] = 1
return {"status": "logged in"}
@app.get("/profile")
async def profile(request: Request):
return {"user_id": request.session.get("user_id")}
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
step |
int |
random | Encryption step |
key |
int |
random | Secret key |
key_env |
str |
None | Environment variable for key |
session_cookie |
str |
"session" |
Cookie name |
max_age |
int |
1209600 | Cookie lifetime in seconds |
path |
str |
"/" |
Cookie path |
same_site |
str |
"lax" |
SameSite flag |
https_only |
bool |
False |
Secure flag |
domain |
str |
None | Cookie domain |
If
stepandkeyare not provided, random values are generated at startup.
Warning: Do not use
EnciphersMiddlewaretogether with Starlette'sSessionMiddleware.
License
Apache-2.0 — Copyright 2026 Mejlad Alsubaie
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastapi_enciphers-0.1.0.tar.gz.
File metadata
- Download URL: fastapi_enciphers-0.1.0.tar.gz
- Upload date:
- Size: 6.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
565a5c7200e16bc76461c7109e58947a137f952ece877ca5433de555e81f9988
|
|
| MD5 |
b4a197112e521edad3a2df0f2f31ba84
|
|
| BLAKE2b-256 |
ebaa592626f74b698872c97d4fae659dfb4b00599e95bb9991ff007c12faf47b
|
Provenance
The following attestation bundles were made for fastapi_enciphers-0.1.0.tar.gz:
Publisher:
publish.yml on mjlad/fastapi-enciphers
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_enciphers-0.1.0.tar.gz -
Subject digest:
565a5c7200e16bc76461c7109e58947a137f952ece877ca5433de555e81f9988 - Sigstore transparency entry: 1809404617
- Sigstore integration time:
-
Permalink:
mjlad/fastapi-enciphers@8f956c8d413d138bbbb762ea09a853287fab5596 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mjlad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8f956c8d413d138bbbb762ea09a853287fab5596 -
Trigger Event:
push
-
Statement type:
File details
Details for the file fastapi_enciphers-0.1.0-py3-none-any.whl.
File metadata
- Download URL: fastapi_enciphers-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
397b4ed325ea4a315225886e1af5c0f07fddf1884e5205b2fa49e5d4632982d4
|
|
| MD5 |
85878c84f9e319a1dea03e3aab35daed
|
|
| BLAKE2b-256 |
44e07f6a9b016d5312f4668a306a8e5b9d4ce722f56ba42fd4584787b105e6d8
|
Provenance
The following attestation bundles were made for fastapi_enciphers-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on mjlad/fastapi-enciphers
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_enciphers-0.1.0-py3-none-any.whl -
Subject digest:
397b4ed325ea4a315225886e1af5c0f07fddf1884e5205b2fa49e5d4632982d4 - Sigstore transparency entry: 1809404641
- Sigstore integration time:
-
Permalink:
mjlad/fastapi-enciphers@8f956c8d413d138bbbb762ea09a853287fab5596 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/mjlad
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@8f956c8d413d138bbbb762ea09a853287fab5596 -
Trigger Event:
push
-
Statement type: