Skip to content
Stack · Flask

Add e-signatures and clickwrap to Flask

To add e-signatures and clickwrap to Flask, call the REST API from your routes. There is no Python package: the server SDK exists for Node.js only. One route creates the session with the secret key and keeps the pinned versions in Flask's signed session cookie, and another route confirms the record. Esign Comply seals each acceptance as an independent record.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

$pip install flask requests python-dotenv
Flask quickstart

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated

Run in Flask before publishing
app.py (excerpt)
# Step 4: create the session with the secret key. The browser gets the client token only.
@app.post("/api/ceremony")
def ceremony():
    origin = request.headers.get("Origin") or request.host_url.rstrip("/")
    status, created = esc(
        "POST",
        "/sessions",
        idempotency_key=f"signup-{SIGNER['external_id']}-{uuid.uuid4()}",
        json={
            "profile": os.environ["ESIGNCOMPLY_PROFILE_ID"],
            "signer": SIGNER,
            "documents": [
                {"document": DOCUMENTS["terms"], "version": "current"},
                {"document": DOCUMENTS["privacy"], "version": "current"},
            ],
            "context": {"url": f"{origin}/signup", "locale": "en-US", "purpose": "account_signup"},
        },
    )
    if status != 201:
        return {"error": created.get("error", {}).get("code")}, 502
    # Flask signs the session cookie: the browser can read the version IDs and cannot change them.
    session["pinned_versions"] = sorted(d["version_id"] for d in created["documents"])
    return {"clientToken": created["client_token"], "apiUrl": created["api_url"], "documents": created["documents"]}
Integrate with Flask

How do you integrate Esign Comply with Flask?

In Flask the integration is four routes in one file. session holds the versions the server pinned in a cookie that Flask signs, so nothing sits in memory and a first run needs no database. The flask command reads .env once python-dotenv is installed, and FLASK_SECRET_KEY gives the cookie its key.

Flask is a lightweight WSGI web application framework. It is designed to make getting started quick and easy, with the ability to scale up to complex applications.

Source: Flask documentation, read on .
Where each part lives in Flask
  • Session routeapp.py
  • The API callapp.py
  • Confirm routeapp.py
  • Document templatetemplates/legal.html

Run on 2026-11-26 with Flask 3.1.3, Werkzeug 3.1.9, Jinja 3.1.6, requests 2.32.5 and python-dotenv 1.2.1 on Python 3.9.25, under flask run, with the browser SDK script build and the conformance check from esigncomply 1.0.4 (run with --timeout 60), against the API in test mode.

Copy-paste prompt

What prompt adds Esign Comply clickwrap to a Flask app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes in Flask, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at /rules.md. Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The prompt generator writes the long version, with your own document and profile IDs.

Pages for each AI tool
Prompt: Esign Comply clickwrap in Flask
Add Esign Comply clickwrap to my Flask app: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/flask.md (the steps and the tested code for Flask)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Flask facts
- There is no Esign Comply package for Python. Do not install or invent one. The routes call the REST API at https://esigncomply.com/v1 with Authorization: Bearer and the secret key, using requests.
- The browser SDK is a script tag: https://esigncomply.com/sdk/v1/esigncomply.js. It defines the global EsignComply.
- The secret key is in the environment variable ESIGNCOMPLY_API_KEY. The flask command reads .env only when python-dotenv is installed. Never print the key.
- Keep the pinned version IDs in flask.session. The session needs a secret key: set FLASK_SECRET_KEY and call app.config.from_prefixed_env(). The cookie is signed, not encrypted: never put a secret in it.
- Jinja escapes values in .html templates. Print the document HTML with the safe filter, unmodified.
- Flask has no CSRF protection of its own. If the project already has a CSRF extension, send its token with both POST requests.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Route for POST /api/ceremony: call POST /v1/sessions with an Idempotency-Key, save the pinned version IDs in flask.session, and return only clientToken, apiUrl and documents.
4. Route for GET /legal/<slug>: render the html from GET /v1/documents/{id}/versions/{version_id}/content inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Route for POST /api/signup/confirm: call GET /v1/records/{id} and require: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the server-owned state. Only then create the account.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:5000/signup --callback http://localhost:5000/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
3 things to watch

What goes wrong when you add e-signatures in Flask?

These are specific to Flask. Each one was seen while the quickstart's code was run, or is in Flask's own documentation.

  • 01

    Flask signs the session cookie and does not encrypt it

    Flask's documentation says the user can look at the contents of the cookie but not modify it. In the test run on Flask 3.1.3 the first part of the cookie decoded from base64 to the two pinned version IDs, and a cookie with a changed payload was treated as empty: the confirm route answered 409. Keep secrets out of session.

    Source: Flask documentation, Quickstart, Sessions, read on .
  • 02

    flask run reads .env only with python-dotenv installed

    With Flask and requests alone, flask run printed Tip: There are .env files present. Install python-dotenv to use them. and stopped with KeyError: 'ESIGNCOMPLY_API_KEY'. With python-dotenv installed it loaded the file before it imported app.py. Flask's documentation says the files are only loaded by the flask command or by calling run().

    Source: Flask documentation, Environment Variables From dotenv, read on .
  • 03

    Jinja escapes the document unless you mark it safe

    The document page has to render the registered version unmodified. In the test run, {{ html }} in legal.html arrived as &lt;h1&gt;Terms of Service&lt;/h1&gt;, because Jinja escapes values in .html templates. With {{ html|safe }} the page carried the heading, and the conformance check passed.

Verifiable

What does Esign Comply record for a signature in Flask?

The same record on every stack and platform. Your Flask code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on Evidence and verification.

  • Observed and asserted fields

    Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

  • A signed receipt

    complete() returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and GET /v1/records/{id}/receipt returns it again.

  • An external timestamp

    An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

  • An offline verifier

    Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source esigncomply-verify, without an account.

Recordrec_Z4m8
simple · L1
RecordedWritten durably, receipt signed with ES256
TimestampedExternal RFC 3161 token over the record hash
AnchoredPublic anchor pending
Checkbox changed by a trusted user eventobserved
Terms of Service, version dv_3kT9observed
Server time 2026-11-21T15:03:20.291Zobserved
Signer email dana@example.orgasserted
record_hash sha256:5be7…example record

Questions about e-signatures in Flask

Is there an Esign Comply SDK for Flask?

No. The server SDK exists for Node.js only, and there is no Flask extension. Flask calls the REST API directly with the secret key, and the quickstart does it with requests in one short function. The browser side is the same SDK as on every stack, loaded from a script tag.

Where do I create the session in Flask?

In a route that handles POST /api/ceremony, with a call to POST /v1/sessions that carries the secret key and an Idempotency-Key. The route returns only the client token, the API URL and the pinned documents to the browser.

Can the visitor change the versions kept in the Flask session?

No. The visitor can read them and cannot change them, because Flask signs the cookie with SECRET_KEY. In the test run a cookie whose payload was edited was treated as empty, and a cookie signed with another key was refused after a restart. Both times the confirm route answered 409.

Does Flask check a CSRF token on the POST routes?

No. Flask has no CSRF protection of its own: its documentation says the place for it is a form validation framework, which Flask does not have. In the test run a POST with no token and the Origin of another site reached the confirm route, which refused the made-up record ID with 409.

Why set FLASK_SECRET_KEY and not app.secret_key in the code?

So the key stays out of the repository. app.config.from_prefixed_env() copies every FLASK_ variable into the configuration, and FLASK_SECRET_KEY becomes SECRET_KEY. Without it the session route answered 500 in the test run, with The session is unavailable because no secret key was set in the log.

Add four routes to your Flask app. Leave the record to us.

Free plan: 10 live signatures a month and a full test mode. No card required.

Flask is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Flask is from Flask's documentation or from a test run, as marked, on . /flask.md is this page as Markdown.

Working with an AI tool? This page is also available as Markdown: /flask.md