Skip to main content

esaalat (Python)

Server-side Esaalat client. It does the three things a merchant backend always writes by hand — the 1-hour token, the idempotency key, and the webhook HMAC — so an integration is three calls instead of forty lines.

  • Locked checkout sessions — create the session on your server, give the browser only the token.
  • Payment intents — create one server-side for platform orders, attach the buyer's reference, read status.
  • Signed webhooks — verify X-Esaalat-Signature over the raw body, with a replay window.
  • No dependencies — standard library only (urllib, hmac, json).

Install

pip install esaalat

Quick start

from esaalat import EsaalatClient

# Reads ESAALAT_CLIENT_ID, ESAALAT_CLIENT_SECRET and ESAALAT_WEBHOOK_SECRET.
esaalat = EsaalatClient.from_env()

# 1. Your server decides the amount; the browser gets only the token.
session = esaalat.create_session(order_id="order-123", amount=5000)
session["session_token"]  # → checkout.open({ sessionToken }) in the browser
session["portal_url"]     # → or send the buyer straight to this page

# 2. Fulfil on the signed webhook, never on the buyer's page.
@app.post("/esaalat/webhooks")
def webhook():
    try:
        event = esaalat.verify_webhook(
            request.data,                      # the RAW body
            request.headers["X-Esaalat-Signature"],
        )
    except EsaalatWebhookError:
        return "", 400

    if event["event"] == "payment.verified":
        mark_order_paid(event["order_id"])     # idempotent on intent_id
    return "", 200

Also available: create_intent(wallet=..., amount=..., order_id=...), retrieve_intent(intent_id), attach_reference(intent_id, reference), list_notes_forms(search=...), retrieve_notes_form(form_id) and format_amount(value).

Checkout questions (notes forms)

A notes form is a reusable set of questions built in the dashboard (Payments → Notes Forms). Pass its id and the hosted checkout asks them; the buyer's answers come back on the intent.

form = esaalat.list_notes_forms()["results"][0]
intent = esaalat.create_intent(wallet=wallet_id, amount=5000, notes_form=form["id"])

current = esaalat.retrieve_intent(intent["id"])
current["notes_form"]      # {"id", "name", "description"} or None
current["notes_answers"]   # [{"id", "label", "type", "value"}] — empty until answered

What it handles for you

Token Issued once per client, cached, refreshed a minute before the JWT's own exp.
Idempotency A UUID per create call, reused on every retry — a 429 or a timeout can never double-book an order.
Retries 429, 5xx and network failures, honouring Retry-After.
Errors EsaalatError with code, status, detail, attr and the API's per-field errors.
Webhooks hmac.compare_digest, optional ±5 min window, 400-shaped EsaalatWebhookError.

Configuration

Argument Environment Default
client_id ESAALAT_CLIENT_ID — (required)
client_secret ESAALAT_CLIENT_SECRET — (required)
webhook_secret ESAALAT_WEBHOOK_SECRET — (needed by verify_webhook)
base_url ESAALAT_BASE_URL https://api.esaalat.com/api/v1
timeout — 20 seconds
max_retries — 2

Every endpoint takes a secret= override in verify_webhook, because each webhook endpoint on the dashboard has its own signing secret.

Notes

  • The client secret is a server secret. Never call this from a browser or ship it in a mobile app; the browser only ever needs the session token.
  • Amounts are whole Yemeni riyals. format_amount(5000.5) refuses before the request leaves your process.
  • The webhook body must be the raw bytes: json.dumps(request.get_json()) will not match the signature.

Development

python -m unittest discover -s tests -t .

License

MIT © Esaalat

Metadata

Release files for esaalat 0.2.0

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

Source distribution (sdist)

Source distribution for esaalat 0.2.0
File Size Uploaded Provenance Actions
esaalat-0.2.0.tar.gz 13.2 kB With provenance Details for esaalat-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for esaalat 0.2.0
File Interpreter ABI Platform Actions
esaalat-0.2.0-py3-none-any.whl Python 3 none any Details for esaalat-0.2.0-py3-none-any.whl

Total release size: 24.0 kB

Release files / esaalat-0.2.0.tar.gz

Download URL esaalat-0.2.0.tar.gz
Size 13.2 kB
Tags Source
SHA-256 checksum
How to use checksums
b84f656fc8b3a76ab19db4b2ca98fdbec34f987191b0be82847df75d451a7007
BLAKE2b-256 checksum
How to use checksums
83854e0768561f94b8cfebd5d2bf5878dadb741ae44dea498fe233430ea42f58
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 12, 2026.

Transparency log

Release files / esaalat-0.2.0-py3-none-any.whl

Download URL esaalat-0.2.0-py3-none-any.whl
Size 10.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
e576f1262601c5c916c0204bca8e93a59bbf37ad56c7a9ffe009eead0c78d9a5
BLAKE2b-256 checksum
How to use checksums
e0e2f8c51be17f45d98d1ac433f13bef25c4dc9a8b47a056cdf429356b0d142d
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 12, 2026.

Transparency log

Security for esaalat 0.2.0

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 esaalat-0.2.0.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 12, 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