# Add e-signatures and clickwrap to Python

> Add e-signatures and clickwrap to a Python app with plain HTTPS calls: POST /v1/sessions and GET /v1/records with urllib. No Python package to install.

Source: https://esigncomply.com/python

Stack · Python

To add e-signatures and clickwrap to Python, call the REST API: there is no Python package, because the server SDK exists for Node.js only. Your server sends `POST /v1/sessions` and `GET /v1/records/{id}` with the secret key, and the browser SDK from a script tag attaches to your own form. Esign Comply seals each acceptance as an independent, verifiable 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.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/python)

No package to install: the standard library is enough

[Python quickstart](https://esigncomply.com/docs/quickstart/python)

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

Last updated November 26, 2026

Run in Python before publishing

**The API call**

app.py (excerpt)

```python
def esc(method, path, body=None, idempotency_key=None):
    """One call to the Esign Comply API. Returns (status, parsed JSON)."""
    headers = {"Authorization": f"Bearer {KEY}", "Accept": "application/json"}
    if body is not None:
        headers["Content-Type"] = "application/json"
    if idempotency_key:
        headers["Idempotency-Key"] = idempotency_key
    data = json.dumps(body).encode() if body is not None else None
    for attempt in range(3):
        try:
            with urlopen(Request(API + path, data=data, headers=headers, method=method), timeout=10) as response:
                return response.status, json.load(response)
        except HTTPError as error:  # urllib raises on 4xx and 5xx: the error envelope is in the body
            # Over the rate limit: wait for Retry-After (5 seconds at most) and try again, twice at most. Nothing else is retried.
            if error.code == 429 and attempt < 2:
                time.sleep(min(float(error.headers.get("Retry-After") or 1), 5))
                continue
            return error.code, json.load(error)
```

**Create the session**

app.py (excerpt)

```python
# Step 4: create the session with the secret key. The browser gets the client token only.
if self.path == "/api/ceremony":
    origin = self.headers.get("Origin") or f"http://{self.headers['Host']}"
    status, session = esc("POST", "/sessions", idempotency_key=f"signup-{SIGNER['external_id']}-{uuid.uuid4()}", body={
        "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 self.send(502, {"error": session.get("error", {}).get("code")})
    pinned[SIGNER["external_id"]] = sorted(d["version_id"] for d in session["documents"])
    return self.send(200, {"clientToken": session["client_token"], "apiUrl": session["api_url"], "documents": session["documents"]})
```

**Confirm**

app.py (excerpt)

```python
# Step 6: confirm the record with the secret key before the account exists.
if self.path == "/api/signup/confirm":
    status, record = esc("GET", f"/records/{quote(str(payload.get('recordId')), safe='')}")
    confirmed = (
        status == 200
        and record["status"] in SEALED
        and record["livemode"] is LIVE
        and record["signer"]["external_id"] == SIGNER["external_id"]
        and sorted(d["version_id"] for d in record["documents"]) == pinned.get(SIGNER["external_id"])
    )
    print(f"confirmed {record['id']} ({record['status']})" if confirmed else "refused", flush=True)
    if not confirmed:
        return self.send(409, {"confirmed": False})
    # Only now create the account, and store record["id"] and record["receipt"] with it.
    return self.send(200, {"confirmed": True, "recordId": record["id"]})
```

Integrate with Python

## How do you integrate Esign Comply with Python?

In Python the whole client is one function: an HTTPS call with the `Authorization` header and a JSON body. The quickstart uses `urllib.request` from the standard library, so nothing comes from PyPI, and it runs on Python 3.9 or later. The same two calls work from `requests`, `httpx`, Django or Flask.

The Python documentation says of its own development server: http.server is not recommended for production.

Source: [Python documentation, http.server](https://docs.python.org/3/library/http.server.html), read on November 23, 2026.

[Python quickstart](https://esigncomply.com/docs/quickstart/python) · [All stacks](https://esigncomply.com/stacks)

Where each part lives in Python

- **The API call** · `app.py`
- **Create the session** · `app.py`
- **Confirm** · `app.py`

Run on 2026-11-26 with Python 3.9.25 and its standard library only, the browser SDK script build, and the conformance check from esigncomply 1.0.4, against the API in test mode.

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Python 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 Python, 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](https://esigncomply.com/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](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap in Python

```python
Add Esign Comply clickwrap to my Python 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/python.md (the steps and the tested code for Python)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Python facts
- There is no Esign Comply package for Python. Do not install or invent one. The server calls the REST API at https://esigncomply.com/v1 with Authorization: Bearer and the secret key, using the HTTP client the project already has.
- 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. Python does not read .env files on its own. Never print the key.
- urllib raises HTTPError on 4xx and 5xx. The Esign Comply error envelope is in the body of that exception: read it.
- 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. Server: POST /api/ceremony calls POST /v1/sessions with an Idempotency-Key, saves the signer ID and the pinned version IDs in server-owned state, and returns only clientToken, apiUrl and documents.
4. Server: GET /legal/terms and /legal/privacy 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. Server: POST /api/signup/confirm calls GET /v1/records/{id} and requires: 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:8000/signup --callback http://localhost:8000/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 Python?

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

- **urllib raises on every 4xx and 5xx**

  `urlopen` raises `HTTPError` when the API refuses a call, and the error envelope is the body of that exception. Catch it and parse it. In the test run a made-up record ID came back as status `404` with the code `not_found` and a message, read from the exception.

- **Python does not read .env files**

  The quickstart reads the key with `os.environ["ESIGNCOMPLY_API_KEY"]`, which raises `KeyError` at startup when the variable is not set. Load the file into the shell that runs the server, or use the settings mechanism of your framework.

- **The conformance check is a Node.js tool**

  The checker that signs your page at three window sizes is the `esigncomply` command line tool. It needs Node.js 20.19 or later, in a folder of its own, whatever language serves the page. Your Python project gets no Node.js files.

## Where are the Python quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[Python quickstart](https://esigncomply.com/docs/quickstart/python)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Long guide

  **[Clickwrap in Django](https://esigncomply.com/guides/django-clickwrap)**

  The same calls in a full Django app: the client, the views, the signup form, the model and the webhook.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature in Python?

The same record on every stack and platform. Your Python 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](https://esigncomply.com/product/evidence).

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

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures in Python

### Is there an Esign Comply SDK for Python?

No. The server SDK exists for Node.js only. A Python server calls the REST API directly with the secret key, and the quickstart does it with `urllib.request` from the standard library. The browser side is the same SDK as on every stack.

### Where do I create the session in Python?

In the server-side handler behind your signing page, with a `POST` to `/v1/sessions` that carries the secret key and an `Idempotency-Key`. The handler returns only the client token, the API URL and the pinned documents to the browser.

### Do I need requests or httpx?

No. The quickstart runs on the standard library alone. With `requests` or `httpx` the calls are the same, and a refused call is then a response to read instead of an exception, which is what the FastAPI quickstart relies on.

### Which Python version does the code need?

Python 3.9 or later. The quickstart was run on Python 3.9.25 with nothing installed from PyPI. It uses f-strings, `ThreadingHTTPServer` and `urllib.request`.

### Does this work with Django and Flask?

Yes. The API calls do not depend on a framework: move the `esc` function into your project and call it from your views. The Django guide on this site is a full app with the model, the views and the webhook.

### Other stacks

- [FastAPI](https://esigncomply.com/fastapi)
- [Node.js](https://esigncomply.com/nodejs)
- [Express](https://esigncomply.com/express)

### Platforms used with Python

- [Supabase](https://esigncomply.com/supabase)
- [Vercel](https://esigncomply.com/vercel)

[All stacks](https://esigncomply.com/stacks) · [All platforms](https://esigncomply.com/platforms) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Call the API from the Python you already run. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/python)

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

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

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
