Flask Payload Shield
Pluggable Flask decorators for encrypting and decrypting request and response payloads.
Installation
pip install flask-payloadshield
Project page: https://pypi.org/project/flask-payloadshield/
For local development:
git clone https://github.com/PayloadShield/FlaskPS.git
cd FlaskPS
python -m venv .venv
# Windows PowerShell
.venv\Scripts\Activate.ps1
# Linux/macOS
# source .venv/bin/activate
python -m pip install -e ".[dev]"
Quick Start
from flask import Flask
from flask_payloadshield import PayloadShield, PayloadShieldEnc
app = Flask(__name__)
PayloadShieldEnc.init({"Key": "12345678901234567890123456789012"})
@app.get("/data")
@PayloadShield.encrypt("aes-gcm-256")
def get_data():
return {"message": "hello"}
@app.post("/process")
@PayloadShield.decrypt("aes-gcm-256")
def process_data(data: dict):
return {"received": data}
@app.post("/secure")
@PayloadShield.crypt("aes-gcm-256")
def secure_endpoint(data: dict):
return {"processed": data}
if __name__ == "__main__":
app.run(debug=True)
Send encrypted requests using this envelope:
{"encrypted": "<encoded payload>"}
The decrypt and crypt decorators inject the decrypted object into the
first route parameter, such as data above. Decryption errors return HTTP
400 with an error field.
Built-in Handlers
| Name | Algorithm | Keys |
|---|---|---|
base64 |
Base64 encoding | None; obfuscation only |
fernet |
Fernet | Key |
aes-gcm-256 |
AES-256-GCM | Key resolving to 32 bytes |
chacha20-poly1305 |
ChaCha20-Poly1305 | Key resolving to 32 bytes |
rsa-hybrid |
RSA-OAEP + AES-256-GCM | PublicKey, PrivateKey |
ecdh-aes-gcm |
ECDH P-256 + AES-256-GCM | ECPublicKey, ECPrivateKey |
ecies |
ECDH P-256 + AES-CTR + HMAC | ECPublicKey, ECPrivateKey |
hpke |
RFC 9180 HPKE with X25519 | HPKEPublicKey, HPKEPrivateKey |
PEM values may be raw key content or file paths. PayloadShieldEnc.init()
resets omitted keys to None and get_config() returns the current config.
Example and Postman
cd examples
python main.py
The example runs on http://127.0.0.1:5000, generates missing RSA, EC, and
X25519 PEM files, and prints ready-to-paste Postman request bodies for every
handler at startup. Use Ctrl+C to stop it.
In another terminal, verify the app:
curl http://127.0.0.1:5000/health
curl http://127.0.0.1:5000/aes
Development
pip install -e ".[dev]"
pytest
Publishing
Set a PyPI API token and run the publishing script from the project root:
export PYPI_TOKEN="pypi-..."
bash publish.sh
The script builds and checks the package before uploading it to
https://pypi.org/project/flask-payloadshield/. The package version in
pyproject.toml must be incremented before publishing a new release.
License
Apache-2.0 - See LICENSE.
📞 Support
- GitHub Issues: https://github.com/PayloadShield/FlaskPS/issues
- PyPI Page: https://pypi.org/project/flask_payloadshield/
- Author: Ganesh Kandu kanduganesh@gmail.com
Release files for flask-payloadshield 1.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| flask_payloadshield-1.0.1.tar.gz | 17.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| flask_payloadshield-1.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.4 kB
Release files / flask_payloadshield-1.0.1.tar.gz
| Download URL | flask_payloadshield-1.0.1.tar.gz |
|---|---|
| Size | 17.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1e3f0260e1a36da95f54e03ab806e71ba16d1b4d5adf2e4c9bf2d96d9df52294
|
|
BLAKE2b-256 checksum How to use checksums |
433ed3b7f56a0fad33c7a0e8e058d317dc0919ec72c42dfcc471a21d1a6bb00b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / flask_payloadshield-1.0.1-py3-none-any.whl
| Download URL | flask_payloadshield-1.0.1-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28b63bea1522c94b515adc1982abede814abb5539522c9d4830f1541d2699207
|
|
BLAKE2b-256 checksum How to use checksums |
91d335ce3d496198e81d0654dd6cb8eb708b48b707c2ebff3787655dba14a425
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|