This release is a pre-release and may not be stable for production use.
sendproof-flask
Serves the Sendproof workbench from a Flask application and runs rollback Preview and Observed Send through Flask's own routing and your view code.
pip install sendproof-flask sendproof-sqlalchemy
from flask import Flask, session
from sendproof_flask import AuthProvider, Identity, Sendproof, preview
from sendproof_sqlalchemy import SQLAlchemyPreview
app = Flask(__name__)
def identity(request) -> Identity | None: # runs in a request context: flask.session works
user = session.get("user")
return user and Identity(user["name"], user["role"], subject=user["id"], authentication_type="session")
Sendproof(
app,
provider=SQLAlchemyPreview(engine, database="inventory_dev"),
identity=identity,
environment="Development", # off in any environment not listed
openapi_url="/openapi.json", # wherever you serve your OpenAPI document
auth_providers=[AuthProvider("Password", "cookie", "/auth/sign-in")],
)
@app.post("/items")
@preview # below the route decorator
def create_item(): ...
Open /sendproof/. The workbench needs an OpenAPI document; Flask has none built in, so serve one
(for example with apispec or flask-smorest) and set openapi_url.
How it works
Sendproof wraps app.wsgi_app. A request to /sendproof/_preview/<path> with exactly
Prefer: tx=rollback is matched against the app's own URL map, executed in-process through the
current app.wsgi_app chain (so WSGI middleware wrapped around Sendproof later also sees the
target path), buffered (1 MiB cap), rolled back, and only then answered with the confirmed envelope.
A before_request hook that runs first checks again that the request still reaches the marked view
and method; a middleware that changed either gets a 409 and no view runs.
Prefer: trace on the original URL commits normally and adds X-Sendproof-Trace for a caller with
a stable Identity.subject; fetch it from /sendproof/_api/traces/{id} as the same caller within
trace_ttl seconds.
- Only
@previewviews are advertised and accepted, and only for their write methods (POST,PUT,PATCH,DELETE) or the methods you pass with@previewon a view registered for them. - Denials. Flask has no dependency layer, so authentication usually happens inside the view. A 401 or 403 response is therefore always treated as a denial and never returned as an envelope. Any other status the view returns, including 409, is the application's answer and appears inside the envelope. An unhandled exception becomes an unconfirmed 500.
- A
Requestis available toidentityandauthorizehooks; do not read the request body in them. - Record outgoing email and similar effects with
sendproof_core.record_email, and skip delivery when it returnsTrue.
Options match sendproof-fastapi.
Data layer
sendproof-sqlalchemy (sync engines). The provider enrolls the engine, so plain SQLAlchemy
sessions, scoped_session, Flask-SQLAlchemy's db.session and raw engine.begin() connections all
share the preview connection. See the coverage notes. A
Flask development server runs requests on threads: with SQLite, previews at the same time block
each other.
Flask-SQLAlchemy
Pass the extension's engine to the provider. db.engine needs an application context, so read it
inside one:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from sendproof_flask import Sendproof, preview
from sendproof_sqlalchemy import SQLAlchemyPreview
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "postgresql+psycopg://app:secret@localhost/inventory_dev"
db = SQLAlchemy(app)
with app.app_context():
engines = list(db.engines.values()) # the default engine plus every SQLALCHEMY_BINDS entry
Sendproof(app, provider=SQLAlchemyPreview(*engines, database="inventory_dev"),
identity=identity, environment="Development", openapi_url="/openapi.json")
@app.post("/items")
@preview
def create_item():
db.session.add(Item(**request.get_json()))
db.session.commit() # a real commit in normal use, a rolled-back one in Preview
return jsonify(id=...), 201
Handlers need no changes. In a preview db.session.commit() ends the emulated transaction,
db.session.rollback() undoes only the work since the last commit, begin_nested() is a real
SAVEPOINT, and after_commit listeners still run. Record emails and other deliveries with
record_email and friends, which return True during a preview, so a listener that sends them is
suppressed. Flask-SQLAlchemy removes the scoped session when each request's application context ends,
which also happens for the in-process request a preview runs.
Verified and limits
Verified with Flask 3.1.3, Flask-SQLAlchemy 3.1.1 and SQLAlchemy 2.1.9, on SQLite, PostgreSQL 17
(psycopg 3.3.9) and MySQL 8.4 (PyMySQL 1.2.4). adapters/python/conformance/fixture_flask_sqlalchemy.py
passed all 11 shared HTTP checks on each, as did the plain-SQLAlchemy fixture_flask.py. The package
tests (flask/tests, 20 tests) cover the same lifecycle, transaction, commit-hook and authorization
cases on SQLite by default. To run them on another database, export BENCH_DATABASE=postgresql or
mysql and BENCH_DATABASE_URL=<disposable database>; the tests drop and recreate their items and
audit tables.
- Enroll every engine. A
SQLALCHEMY_BINDSengine that is not passed toSQLAlchemyPreviewis not rolled back and its rows are not captured; its writes persist even in a preview. Passdb.engines.values(). - Dialects. Verified on SQLite, PostgreSQL and MySQL. The provider uses
SAVEPOINT. MariaDB and Oracle remain unverified. The provider reports SQL Server previews as unavailable. AnAUTOCOMMITengine cannot be rolled back and previews are refused. - Not tested. Flask-Login, Flask async views, Flask-Migrate and
AsyncEngineunder Flask. - Commit hooks run during a preview. Code in
after_committhat has side effects outside the database must go throughrecord_*, or it will deliver for real.
Metadata
Release files for sendproof-flask 0.1.0a1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| sendproof_flask-0.1.0a1.tar.gz | 11.0 kB | With provenance | Details for sendproof_flask-0.1.0a1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| sendproof_flask-0.1.0a1-py3-none-any.whl | Python 3 | none | any | Details for sendproof_flask-0.1.0a1-py3-none-any.whl |
Total release size: 23.5 kB
Release files / sendproof_flask-0.1.0a1.tar.gz
| Download URL | sendproof_flask-0.1.0a1.tar.gz |
|---|---|
| Size | 11.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e3141b440aeb11b6835cda69d19da0c509de526592e23f1b19746facb41bda8
|
|
BLAKE2b-256 checksum How to use checksums |
2ffb63582af6695cfbac340730672a983f730f635d49e0906852618cc6d1d82f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logRelease files / sendproof_flask-0.1.0a1-py3-none-any.whl
| Download URL | sendproof_flask-0.1.0a1-py3-none-any.whl |
|---|---|
| Size | 12.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
38a41f4469386f520c363800aeb12450f783c8fe9ddd66ff367edf70ae32d092
|
|
BLAKE2b-256 checksum How to use checksums |
9cf5f763d7026c0f836a13ba478a06434e13b4c9cff1096311643c9915afc151
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logSecurity for sendproof-flask 0.1.0a1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for sendproof_flask-0.1.0a1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.