Skip to main content
Pre-release

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 @preview views are advertised and accepted, and only for their write methods (POST, PUT, PATCH, DELETE) or the methods you pass with @preview on 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 Request is available to identity and authorize hooks; do not read the request body in them.
  • Record outgoing email and similar effects with sendproof_core.record_email, and skip delivery when it returns True.

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_BINDS engine that is not passed to SQLAlchemyPreview is not rolled back and its rows are not captured; its writes persist even in a preview. Pass db.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. An AUTOCOMMIT engine cannot be rolled back and previews are refused.
  • Not tested. Flask-Login, Flask async views, Flask-Migrate and AsyncEngine under Flask.
  • Commit hooks run during a preview. Code in after_commit that has side effects outside the database must go through record_*, or it will deliver for real.

Metadata

Release files for sendproof-flask 0.1.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sendproof-flask 0.1.0a2
File Size Uploaded Provenance Actions
sendproof_flask-0.1.0a2.tar.gz 11.5 kB With provenance Details for sendproof_flask-0.1.0a2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for sendproof-flask 0.1.0a2
File Interpreter ABI Platform Actions
sendproof_flask-0.1.0a2-py3-none-any.whl Python 3 none any Details for sendproof_flask-0.1.0a2-py3-none-any.whl

Total release size: 24.6 kB

Release files / sendproof_flask-0.1.0a2.tar.gz

Download URL sendproof_flask-0.1.0a2.tar.gz
Size 11.5 kB
Tags Source
SHA-256 checksum
How to use checksums
84374110b456e712e599948f0d9b78fae007cc3dcae75a24bb01571383b05e49
BLAKE2b-256 checksum
How to use checksums
07ea03cfddb4d8921d13112aefcb06cee9a876df42d6bbffdcc5352bd1833296
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 24, 2026.

Transparency log

Release files / sendproof_flask-0.1.0a2-py3-none-any.whl

Download URL sendproof_flask-0.1.0a2-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
f724c4fb5b46b150e30fd9d97bc24cb3fca9b5f6d85cef7da9f43e82c59d58ec
BLAKE2b-256 checksum
How to use checksums
38bac552d468af9fc18dcc981f1dd467730c3eed267e1621a074717972f0a789
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 24, 2026.

Transparency log

Security for sendproof-flask 0.1.0a2

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.

Select from 2 files

Attestation for sendproof_flask-0.1.0a2.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 24, 2026.

Transparency log

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page