Skip to main content

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

Metadata

Release files for ab-ecosystem-python 0.1.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for ab-ecosystem-python 0.1.4
File Size Uploaded Provenance
ab_ecosystem_python-0.1.4.tar.gz 7.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ab-ecosystem-python 0.1.4
File Interpreter ABI Platform
ab_ecosystem_python-0.1.4-py3-none-any.whl Python 3 none any Details

Total release size: 18.9 kB

Release files / ab_ecosystem_python-0.1.4.tar.gz

Download URL ab_ecosystem_python-0.1.4.tar.gz
Size 7.7 kB
Tags Source
SHA-256 checksum
How to use checksums
4b10a29667432d145c1ebf8b009835ae4a41360e6a73ead02947d03005f03fbf
BLAKE2b-256 checksum
How to use checksums
dce52fe88a11c1b69451098778a0402bdfe6459aee58a80c3c97361762b20701
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Release files / ab_ecosystem_python-0.1.4-py3-none-any.whl

Download URL ab_ecosystem_python-0.1.4-py3-none-any.whl
Size 11.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfc552a0986e2269174e136866e8ef904a2479b83ec59f6883017f00efc71604
BLAKE2b-256 checksum
How to use checksums
f141a439793407061f83522f6e8d284abbcee8a03ba197a5cf67906f6d5b9ab0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.0

Security for ab-ecosystem-python 0.1.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page