Pre-release
This release is a pre-release and may not be stable for production use.
ppx-client
Python client for the Preference Profile Exchange (PPX) reference provider and any conformant implementation.
Install
pip install ppx-client
Requires Python 3.11+. Published version: 0.1.0a1 (PyPI).
Alpha, tracking a draft specification. Expect breaking changes. The version is
0.1.0a1on PyPI and0.1.0-alpha.1on npm — the same release in each ecosystem's required format.
Quick start (sync)
from ppx_client import (
PpxClient, GrantRequestInput, consent_redirect_url, generate_pkce,
)
with PpxClient(base_url="https://api.provider.app") as ppx:
# PKCE is mandatory and S256-only. Keep `verifier` in memory; it is sent
# only in the token exchange. The provider stores only the challenge.
pkce = generate_pkce()
req = ppx.request_grant(GrantRequestInput(
client_id="my-app",
subject_id="did:example:user-123",
purposes=["recommendation"],
allowed_domains=["fragrance"],
allowed_namespaces=["fragrance"],
allowed_operations=["read"],
cross_domain_transfer="deny",
writeback_policy="review_required",
requested_duration_days=30,
code_challenge=pkce.challenge,
# Matched EXACTLY against what you registered. Not a query parameter
# on the consent URL any more, so nobody can rewrite it in transit.
redirect_uri="https://my-app.example/callback",
))
# req.request_token is the capability, returned ONCE. Hold it in memory.
# Never log it, never put it in a URL.
# Send the user here to review and approve. This URL is safe to treat as
# public: the id in it exchanges for nothing on its own.
consent_url = consent_redirect_url(
"https://app.provider.app",
req.grant_request_id,
)
# After approval, exchange. The id alone is NOT enough.
tok = ppx.mint_token(
req.grant_request_id,
req.request_token,
pkce.verifier,
client_id="my-app",
# client_secret="…" as well, if you registered as a confidential client
)
# Use it to read scoped claims
profile = ppx.effective_profile(
context={"climate": "hot_humid"},
requested_namespaces=["fragrance"],
token=tok.access_token,
)
Async
import asyncio
from ppx_client import PpxAsyncClient, GrantRequestInput
async def main():
async with PpxAsyncClient(base_url="https://api.provider.app") as ppx:
card = await ppx.discovery_card()
print(card.name, card.supported_namespaces)
asyncio.run(main())
Grant re-use
from ppx_client import PpxGrantRevokedError
try:
fresh = ppx.refresh("my-app", cached_grant_id)
except PpxGrantRevokedError:
# Clear cache, re-run the full approval flow
cached_grant_id = None
AG-UI consent event streaming
from ppx_client import subscribe_ag_ui
for event in subscribe_ag_ui(f"https://api.provider.app/v1/ag-ui/consent/{req_id}"):
print(event["type"], event)
if event["type"] == "RUN_FINISHED":
break
Async variant: subscribe_ag_ui_async.
License
Apache-2.0.
Metadata
Release files for ppx-client 0.1.0a4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| ppx_client-0.1.0a4.tar.gz | 21.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| ppx_client-0.1.0a4-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 45.6 kB
Release files / ppx_client-0.1.0a4.tar.gz
| Download URL | ppx_client-0.1.0a4.tar.gz |
|---|---|
| Size | 21.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
fc0527fc734b95895f4e1d3bdb043d8368fe2c197777406c3829139ba1792de9
|
|
BLAKE2b-256 checksum How to use checksums |
acabce4a9daa3009f60eb48f8b8e511fbf6226f1452a9baf52706326dde3f758
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|
Release files / ppx_client-0.1.0a4-py3-none-any.whl
| Download URL | ppx_client-0.1.0a4-py3-none-any.whl |
|---|---|
| Size | 23.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
534ed5be2209b6d23ded90632eaee0682f247c60cf14d6ded8b45c0fac5d5928
|
|
BLAKE2b-256 checksum How to use checksums |
3efd157db4fdfbe1b7c19b5cf5794c5bc1a7f3b1e85c73c40fd5ce18fc2cff7d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.12.3
|