Metadata-Version: 2.4
Name: fastapi-enciphers
Version: 0.1.0
Summary: Encrypted session middleware for FastAPI using enciphers
Project-URL: Homepage, https://github.com/mjlad/fastapi-enciphers
Author: Mejlad Alsubaie
License: Apache-2.0
License-File: LICENSE
Keywords: enciphers,encryption,fastapi,session,starlette
Classifier: Development Status :: 4 - Beta
Classifier: Framework :: FastAPI
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Security :: Cryptography
Requires-Python: >=3.11
Requires-Dist: enciphers
Requires-Dist: orjson
Requires-Dist: starlette>=0.20
Description-Content-Type: text/markdown

# fastapi-enciphers

Encrypted session middleware for FastAPI using [enciphers](https://pypi.org/project/enciphers/).

Replaces Starlette's default signed cookie session with a fully encrypted one.

## Installation

```bash
pip install fastapi-enciphers
```

## Usage

```python
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
