Skip to main content

Python SDK for the Partner Ecosystem: JWKS-based auth verification and server-to-server actions.

Project description

ab-ecosystem-python

Python SDK for the Partner Ecosystem: JWKS-based auth verification and server-to-server actions.

Install

pip install ab-ecosystem-python

Quick start

Initialise once at start-up, then call the user methods anywhere — either via the module-level helpers (they use the process-wide singleton) or on the client returned by init.

from ab_ecosystem import init, get_user_profile, get_user_subscription

init(
    api_url="https://api.example.com",
    project_id="proj_123",
    project_secret="super-secret",
)

# module-level (singleton)
profile = get_user_profile(access_token=user_jwt)

# or on the instance
client = init(api_url="...", project_id="...", project_secret="...")
subscription = client.get_user_subscription(access_token=user_jwt)

Methods

Method Endpoint
get_user_profile() GET /api/v1/projects/:project_id/me
get_user_wallet() GET /api/v1/projects/:project_id/me
get_user_credit_wallet() GET /api/v1/projects/:project_id/credit-wallets
get_user_subscription() GET /api/v1/projects/:project_id/subscription
send_deduction_request() POST /api/v1/projects/:project_id/credit-wallets/:wallet_id/deduct
ping() GET /ping

:project_id is filled from your config. Every call sends the project credentials via HTTP Basic auth plus the x-project-id header.

Per-user authentication

Each user method accepts access_token and user_id:

  • access_token (the end-user's JWT) → forwarded as Authorization: Bearer <token>.
  • user_id (when no access_token) → keeps the project HTTP Basic auth and adds a user-id header so the API can resolve the user.
  • neither → project HTTP Basic auth only.
sdk.get_user_profile(access_token=user_jwt)
sdk.get_user_profile(user_id="user_123")

Deductions

from ab_ecosystem import send_deduction_request, DeductionRequest

# amount is required; meta / reference / note default to {} / "" / ""
send_deduction_request(
    "wallet_1",
    DeductionRequest(amount=10, meta={"order_id": "o_1"}, reference="ref_1", note="usage"),
    user_id="user_123",
)

# a plain dict works too
send_deduction_request("wallet_1", {"amount": 5}, access_token=user_jwt)

Verifying incoming tokens

The Node SDK ships an Express middleware; in Python the framework-agnostic core is exposed instead, so you can wire it into Flask, FastAPI, Django, etc.

from ab_ecosystem import verify_token, extract_bearer_token

token = extract_bearer_token(request.headers.get("authorization"))
claims = verify_token(token)          # raises jwt.PyJWTError on failure

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

ab_ecosystem_python-0.1.2.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

ab_ecosystem_python-0.1.2-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file ab_ecosystem_python-0.1.2.tar.gz.

File metadata

  • Download URL: ab_ecosystem_python-0.1.2.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for ab_ecosystem_python-0.1.2.tar.gz
Algorithm Hash digest
SHA256 c5044624ffaeb9997a9e2350ae76c9c962c0d2cee31381f07b7d4b4595a69bda
MD5 2a1eacb455d7f22f5270a0459d9faffa
BLAKE2b-256 fd74f22d9c047a6908529dc90b4774c21798f6c6a662bebe0cd73c88f127bdcb

See more details on using hashes here.

File details

Details for the file ab_ecosystem_python-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for ab_ecosystem_python-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 644e9020d1f620334dfd8084c0aa1dd030e58676eb9342e1c7d220a979867dad
MD5 882bdf0545ea2628fe92e90156931b0f
BLAKE2b-256 169e2c68bc01622f5789343a4ac02539fbeb92e1353db577149c361e318f8554

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