Skip to main content

Python SDK for Elav8 Paga — Sign in with Elav8 (OAuth 2.1 + PKCE), offline token verification, entitlements, checkout/portal, and webhook verification.

Project description

elav8 (Python SDK)

Python SDK for Elav8 / Paga — "Sign in with Elav8" (OAuth 2.1 + PKCE), offline access-token verification, entitlements, hosted checkout / customer portal, and webhook signature verification. Mirrors the JavaScript @elav8/paga.

  • Offline JWT verification against Elav8's JWKS (no per-request network call).
  • One-line FastAPI route protection.
  • Small dependency surface: PyJWT, cryptography, httpx.

Install

pip install elav8-paga
# with the FastAPI helper:
pip install "elav8-paga[fastapi]"

Verify an access token (offline)

from paga import verify_access_token, Elav8Error

try:
    claims = verify_access_token(token, issuer="https://billing.example.com/api/auth")
    user_id = claims["sub"]
except Elav8Error:
    ...  # 401

Trade-off: verification is offline, so a token revoked before its exp (~10 min) stays accepted until it expires. For sensitive operations, re-check server state (e.g. entitlements) rather than trusting the token alone.

Protect a FastAPI route (one line)

from fastapi import Depends, FastAPI
from paga.fastapi import require_user

app = FastAPI()
authed = require_user(issuer="https://billing.example.com/api/auth")

@app.get("/me")
def me(user: dict = Depends(authed)):
    return {"sub": user["sub"]}

Sign in with Elav8 (OAuth 2.1 + PKCE)

from paga import Elav8OAuth

oauth = Elav8OAuth(
    issuer="https://billing.example.com/api/auth",
    client_id="client_...",
    redirect_uri="https://app.example.com/callback",
)

# 1. Begin sign-in — persist state + code_verifier in the session, redirect to .url
flow = oauth.start()

# 2. On your callback route:
tokens = oauth.exchange_code(code, code_verifier)
# tokens.access_token is a JWT verifiable with verify_access_token(...)

Server API (secret key)

import os
from paga import Elav8ServerClient, CustomerInput

elav8 = Elav8ServerClient(
    secret_key=os.environ["ELAV8_SECRET_KEY"],
    base_url="https://billing.example.com",
    webhook_secret=os.environ.get("ELAV8_WEBHOOK_SECRET"),
)

snapshot = elav8.get_entitlements("user_1")
if snapshot.entitlements.get("pro"):
    ...

checkout = elav8.create_checkout(
    plan="pro",
    customer=CustomerInput(email="a@b.com", external_user_id="user_1"),
    success_url="https://app.example.com/welcome",
    cancel_url="https://app.example.com/pricing",
)
# redirect the customer to checkout.url

Verify a webhook

event = elav8.construct_webhook_event(raw_body, signature_header)

Elav8 signs each webhook with x-elav8-signature: t=<unix>,v1=<hmac-sha256-hex> over "{t}.{raw_body}"; the timestamp blocks replays. Always pass the raw request body.

License

Proprietary — internal to Elav8 until open-sourced.

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

elav8_paga-0.1.0.tar.gz (10.1 kB view details)

Uploaded Source

Built Distribution

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

elav8_paga-0.1.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file elav8_paga-0.1.0.tar.gz.

File metadata

  • Download URL: elav8_paga-0.1.0.tar.gz
  • Upload date:
  • Size: 10.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for elav8_paga-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8b0beffcbbd0a7848cbc222fdd342085ecfc756e7df1e84c03255885fb30a1c0
MD5 ba629f1acd628518227306d9d03e92f7
BLAKE2b-256 24a3b9444e24bd35742adf0ff88e1b20ec743285a150b1c6df8ebc3366e4cc03

See more details on using hashes here.

Provenance

The following attestation bundles were made for elav8_paga-0.1.0.tar.gz:

Publisher: release-python.yml on ELAV8-Builds/Paga

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file elav8_paga-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: elav8_paga-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for elav8_paga-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb1f67a91ccf3b777e7f4cbcb85bc633ffee56faf8dc9d559ed792b833851536
MD5 6a638dca8151c5ebcbe0b8f9df7e00f3
BLAKE2b-256 9e18bda573a4ed0711763ea7bc1da802a5a4f933162a3f2f6a04483bd21046aa

See more details on using hashes here.

Provenance

The following attestation bundles were made for elav8_paga-0.1.0-py3-none-any.whl:

Publisher: release-python.yml on ELAV8-Builds/Paga

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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