Skip to main content

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 / timeout
  • KeverdAPIError — non-2xx from the API (status_code, body)
  • KeverdSignatureError — bad webhook signature

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

keverd-2.0.1.tar.gz (6.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

keverd-2.0.1-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file keverd-2.0.1.tar.gz.

File metadata

  • Download URL: keverd-2.0.1.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for keverd-2.0.1.tar.gz
Algorithm Hash digest
SHA256 3096329d96f38e64dd012d9cdececbd6d6934ed8fa76c36b8c5b7ff85ad0f3bc
MD5 da8fbe218ee2a5a9466228a62cba3dc8
BLAKE2b-256 112290ecdc25be9bfdd1598b46a70804f6c85150a97d3d3da5f7929139711498

See more details on using hashes here.

File details

Details for the file keverd-2.0.1-py3-none-any.whl.

File metadata

  • Download URL: keverd-2.0.1-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for keverd-2.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4e6eccb21d3456a0b98c811102dc1498217996169e7d37f5d40066b9e59c1a2a
MD5 a27118c4700ec38e016415ebaa860b52
BLAKE2b-256 117aa1353d4d0b273c059b5db3b323aa3192c1762b7001361fbbf615885bfefe

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page