Server-side Python SDK for Keverd — verify events and handle webhooks
Project description
keverd
Server-side Python SDK for Keverd. Verify browser/mobile event_ids and handle signed webhooks.
Python 3.9+ · zero runtime dependencies · works with Flask, FastAPI, Django, and any Python backend.
Install
pip install keverd
Quick start
import os
from keverd import Keverd
keverd = Keverd(secret_key=os.environ["KEVERD_SECRET_KEY"]) # kv_sk_live_… or kv_sk_test_…
# event_id comes from the browser/mobile SDK after fingerprinting
result = keverd.verify(event_id)
if result.get("action") == "block":
# reject the request
...
elif result.get("action") == "allow":
# continue
...
verify() maps to POST /v2/verify and is the only billable decision read. Keep secret keys on the server.
FastAPI example
import os
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
from keverd import Keverd
app = FastAPI()
keverd = Keverd(secret_key=os.environ["KEVERD_SECRET_KEY"])
class LoginBody(BaseModel):
event_id: str
email: str
password: str
@app.post("/login")
def login(body: LoginBody):
risk = keverd.verify(body.event_id)
if risk.get("action") == "block":
raise HTTPException(status_code=403, detail={"error": "Blocked", "reasons": risk.get("reasons")})
# …authenticate user…
return {"ok": True, "visitor_id": risk.get("visitor_id")}
Webhooks (optional)
Sync verify() is enough for most flows. Configure a webhook in the dashboard when you want push delivery.
import os
from fastapi import FastAPI, Request, Response
from keverd import Keverd
app = FastAPI()
keverd = Keverd(secret_key=os.environ["KEVERD_SECRET_KEY"])
@app.post("/webhooks/keverd")
async def keverd_webhook(request: Request):
raw = await request.body() # raw bytes — do not parse first
event = keverd.webhooks.construct_event(
raw,
request.headers.get("x-keverd-signature", ""),
os.environ["KEVERD_WEBHOOK_SECRET"], # whsec_…
)
if event["type"] == "verification.completed":
verification = event["data"]["object"]
# same shape as verify()
return Response(status_code=200)
API
| Method | Description |
|---|---|
Keverd(secret_key, base_url=…, timeout=…) |
Create a client |
keverd.verify(event_id) |
Billable verify → risk decision + signals |
keverd.webhooks.construct_event(payload, signature, secret) |
Verify inbound webhook signature |
Errors
KeverdError— validation / network / timeoutKeverdAPIError— non-2xx from the API (status_code,body)KeverdSignatureError— bad webhook signature
License
MIT
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 keverd-2.0.0.tar.gz.
File metadata
- Download URL: keverd-2.0.0.tar.gz
- Upload date:
- Size: 6.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
25486cb1008eb5725ef29bc5402ab9f94a64d5fe35b942bc8023c7d0080249e3
|
|
| MD5 |
edac113ec163d4c90c5777c8cea9dd51
|
|
| BLAKE2b-256 |
eacf4b326cce13d29f780f43d8120c27fb2106747e38297f5cf39be9ff81fecf
|
File details
Details for the file keverd-2.0.0-py3-none-any.whl.
File metadata
- Download URL: keverd-2.0.0-py3-none-any.whl
- Upload date:
- Size: 7.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
636a06587ae9b11359e20ce30843918ac9dcc01c28aa4fc0d9aecd0db96cef5d
|
|
| MD5 |
a023264adea578adb9063f90e36e935d
|
|
| BLAKE2b-256 |
df7d02618f2517d0f8a8b2d8997b1c0a1c235430d71d7902d995bc0e7f275ae0
|