Python client for StateSet Agentic Commerce Protocol Handler
Project description
stateset-acp
Official Python client for the StateSet Agentic Commerce Protocol (ACP) Handler.
Installation
pip install stateset-acp
Quick Start
HTTP Client
import asyncio
from stateset_acp import AcpHttpClient
async def main():
async with AcpHttpClient(
base_url="http://localhost:8080",
api_key="your_api_key",
) as client:
# Create a checkout session
session = await client.create_checkout_session(
items=[{"id": "prod_123", "quantity": 1}],
)
# Update with customer info
session = await client.update_checkout_session(
session_id=session.id,
customer={
"billing_address": {
"name": "John Doe",
"email": "john@example.com",
"line1": "123 Main St",
"city": "San Francisco",
"region": "CA",
"postal_code": "94102",
"country": "US",
},
},
)
# Complete checkout
result = await client.complete_checkout_session(
session_id=session.id,
payment={"delegated_token": "tok_xxx"},
)
print(f"Order ID: {result.order.id}")
asyncio.run(main())
gRPC Client
import asyncio
from stateset_acp import AcpGrpcClient
async def main():
async with AcpGrpcClient(
address="localhost:50051",
api_key="your_api_key",
) as client:
session = await client.create_checkout_session(
items=[{"id": "prod_123", "quantity": 1}],
)
print(f"Session ID: {session.id}")
asyncio.run(main())
API Reference
AcpHttpClient
| Method | Description |
|---|---|
create_checkout_session(items, customer?, fulfillment?) |
Create a new checkout session |
get_checkout_session(session_id) |
Get an existing session |
update_checkout_session(session_id, items?, customer?, fulfillment?) |
Update session details |
complete_checkout_session(session_id, payment, customer?, fulfillment?) |
Complete with payment |
cancel_checkout_session(session_id) |
Cancel a session |
delegate_payment(request) |
Create PSP vault token |
health_check() |
Check service health |
AcpGrpcClient
| Method | Description |
|---|---|
connect() |
Establish gRPC connection |
close() |
Close connection |
create_checkout_session(items, customer?, fulfillment?) |
Create a new checkout session |
get_checkout_session(session_id) |
Get an existing session |
update_checkout_session(session_id, items?, customer?, fulfillment?) |
Update session |
complete_checkout_session(session_id, payment, customer?, fulfillment?) |
Complete with payment |
cancel_checkout_session(session_id) |
Cancel a session |
delegate_payment(request) |
Create PSP vault token |
Configuration
from stateset_acp import AcpClientConfig
config = AcpClientConfig(
base_url="http://localhost:8080", # HTTP base URL
grpc_address="localhost:50051", # gRPC address
api_key="your_api_key", # API key for authentication
timeout=30.0, # Request timeout in seconds
)
Error Handling
from stateset_acp import AcpHttpClient, AcpApiError
try:
await client.create_checkout_session(items=[])
except AcpApiError as e:
print(f"Type: {e.type}")
print(f"Code: {e.code}")
print(f"Message: {e}")
print(f"Param: {e.param}")
print(f"Status: {e.status_code}")
Types
All Pydantic models are exported:
from stateset_acp import (
CheckoutSession,
CheckoutSessionStatus,
LineItem,
Money,
Customer,
Address,
Order,
# ... and more
)
Building gRPC Support
To use the gRPC client, you need to generate the protobuf files:
cd bindings/python
python -m grpc_tools.protoc \
-I./stateset_acp/proto \
--python_out=./stateset_acp/proto \
--grpc_python_out=./stateset_acp/proto \
./stateset_acp/proto/acp_handler.proto
Development
# Install with dev dependencies
pip install -e ".[dev]"
# Run tests
pytest
# Format code
black stateset_acp
# Type checking
mypy stateset_acp
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
stateset_acp-1.0.0.tar.gz
(12.5 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stateset_acp-1.0.0.tar.gz.
File metadata
- Download URL: stateset_acp-1.0.0.tar.gz
- Upload date:
- Size: 12.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ce9e7c78f9893b6f75e88a5bd9b91093b0a67adb5816c4968a160c48c63ab444
|
|
| MD5 |
912fe0f5639cab4262e3f7269e0f25f4
|
|
| BLAKE2b-256 |
1279885e3bfe356c6c4da97f4b62b1473d9aa84fd621f60c4de2ea1060eaf717
|
File details
Details for the file stateset_acp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: stateset_acp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 13.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.16
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4ba01ba5bf14952f26d224f96a75a3558597429b30e4005c92a7520fbdc2d8f6
|
|
| MD5 |
fb71f563c27c7f4fecf72422151774bc
|
|
| BLAKE2b-256 |
4a1cbfc4928a967e70b382b03af1e419ca689ad076e2e180f6da43ad866222a1
|