Skip to main content

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 step and key are not provided, random values are generated at startup.

Warning: Do not use EnciphersMiddleware together with Starlette's SessionMiddleware.

License

Apache-2.0 — Copyright 2026 Mejlad Alsubaie

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastapi_enciphers-0.1.0.tar.gz (6.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastapi_enciphers-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

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

Hashes for fastapi_enciphers-0.1.0.tar.gz
Algorithm Hash digest
SHA256 565a5c7200e16bc76461c7109e58947a137f952ece877ca5433de555e81f9988
MD5 b4a197112e521edad3a2df0f2f31ba84
BLAKE2b-256 ebaa592626f74b698872c97d4fae659dfb4b00599e95bb9991ff007c12faf47b

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_enciphers-0.1.0.tar.gz:

Publisher: publish.yml on mjlad/fastapi-enciphers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file fastapi_enciphers-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for fastapi_enciphers-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 397b4ed325ea4a315225886e1af5c0f07fddf1884e5205b2fa49e5d4632982d4
MD5 85878c84f9e319a1dea03e3aab35daed
BLAKE2b-256 44e07f6a9b016d5312f4668a306a8e5b9d4ce722f56ba42fd4584787b105e6d8

See more details on using hashes here.

Provenance

The following attestation bundles were made for fastapi_enciphers-0.1.0-py3-none-any.whl:

Publisher: publish.yml on mjlad/fastapi-enciphers

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page