ESRating Python SDK — typed client for the Distribution Hub API + webhook signature verification.
Project description
esrating
Python SDK for the ESRating Distribution Hub API. Mints embed sessions, confirms external payments, verifies webhook signatures.
Install
pip install esrating
Requires Python 3.9+.
Quick start
import os
from esrating import ESRating
esrating = ESRating(api_key=os.environ["ESRATING_SK_LIVE"])
session = esrating.embed.create_session(
user_id="partner-user-123",
email="agent@partner.com",
metadata={"partnerOrderId": "abc"},
)
print(session["session_url"])
Webhook verification (Flask example)
from flask import Flask, request, jsonify
from esrating import ESRating, WebhookSignatureError
app = Flask(__name__)
esrating = ESRating()
@app.post("/webhooks/esrating")
def esrating_webhook():
try:
event = esrating.webhooks.construct_event(
raw_body=request.get_data(as_text=True), # CRITICAL: raw bytes, not parsed
signature=request.headers.get("X-ESRating-Signature"),
secret=os.environ["ESRATING_WEBHOOK_SECRET"],
)
except WebhookSignatureError as exc:
return jsonify(error=str(exc)), 400
if event["event"] == "quote.bound":
on_quote_bound(event["data"])
elif event["event"] == "policy.issued":
on_policy_issued(event["data"])
return jsonify(received=True)
Confirm an external payment
esrating.embed.confirm_external_payment(
quote_id="quote_abc123",
external_payment_id="pi_partner_xyz",
amount_cents=250_000,
method="card",
)
Idempotent — retrying with the same external_payment_id is safe.
Errors
from esrating import ESRating, AuthError, ForbiddenError, RateLimitError
import time
try:
esrating.embed.create_session(user_id="...", email="...")
except AuthError:
# sk_ key bad
raise
except ForbiddenError as exc:
# Distributor paused, KYC missing, etc.
print(exc)
except RateLimitError as exc:
if exc.retry_after_seconds:
time.sleep(exc.retry_after_seconds)
# retry
License
Apache-2.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file esrating-0.1.0.tar.gz.
File metadata
- Download URL: esrating-0.1.0.tar.gz
- Upload date:
- Size: 6.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
09b253629ac941b0649ca8ef12dfc4aa0128d8fa2dcfaf4e9450380030d4fce3
|
|
| MD5 |
6180969ce780d9263fb564a8d43e0dff
|
|
| BLAKE2b-256 |
62e576af2a47001bedb994c7651aac8ebae347473ce60ec7a93aee97b811596a
|
File details
Details for the file esrating-0.1.0-py3-none-any.whl.
File metadata
- Download URL: esrating-0.1.0-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
583d661159f484d2ddc0791eb458a7cf1e36d996db47225e271d6cfb2ed073f5
|
|
| MD5 |
131420ca29b84c72fbb4cef7f65f992f
|
|
| BLAKE2b-256 |
117c0a71652946db26f873e0d5ebf832b2c3d4a415abefd284f8adeb77f72715
|