Strands UCP
Universal Commerce Protocol (UCP) tools for Strands Agents
Enable agentic commerce experiences with full UCP protocol support: discovery, checkout, orders, payments, and extensions.
🚀 Features
- 🔍 Discovery - Query merchant capabilities, services, and payment handlers
- 🛒 Checkout - Full lifecycle management (create → update → complete)
- 📦 Orders - Get, list, cancel, and update orders
- 💰 Payments - Multi-handler support with automatic header management
- 🔐 Security - Request signature support (parameter + env var)
- 🎟️ Extensions - Discounts, fulfillment, refunds, returns, disputes
- 🔧 Custom - Passthrough for any UCP endpoint
📦 Installation
pip install strands-ucp
🎯 Quick Start
from strands_ucp import ucp_discover, ucp_checkout_session, ucp_apply_discount, ucp_complete_checkout
# 1. Discover merchant capabilities
discovery = ucp_discover("https://shop.example.com")
handlers = discovery["body"]["payment"]["handlers"]
# 2. Create checkout session (with optional signature)
checkout = ucp_checkout_session(
merchant_url="https://shop.example.com",
line_items=[
{"item": {"id": "product_123", "title": "Widget"}, "quantity": 2}
],
currency="USD",
payment_handlers=handlers,
buyer={"full_name": "John Doe", "email": "john@example.com"},
request_signature="eyJhbGc..." # Optional: JWT/signed token
)
# 3. Apply discount code
checkout = ucp_apply_discount(
merchant_url="https://shop.example.com",
checkout_id=checkout["checkout_id"],
discount_codes=["SAVE10"],
current_checkout=checkout["body"]
)
# 4. Complete checkout
order = ucp_complete_checkout(
merchant_url="https://shop.example.com",
checkout_id=checkout["checkout_id"],
payment_instrument={
"type": "card",
"handler_id": "mock_payment_handler",
"credential": {"token": "success_token"}
}
)
print(f"Order created: {order['order_id']}")
🔐 Security & Signatures
Request Signatures
Production UCP merchants require request signatures for security. Provide them via:
1. Function Parameter (Recommended)
ucp_checkout_session(
merchant_url="https://shop.example.com",
request_signature="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
# ... other params
)
2. Environment Variable
export UCP_REQUEST_SIGNATURE="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
# Signature automatically loaded from env var
ucp_checkout_session(
merchant_url="https://shop.example.com",
# ... other params
)
Parameter takes precedence over env var. If neither is provided, the request-signature header is omitted (discovery endpoints typically don't require signatures).
Generating Signatures
Request signatures are typically JWT tokens signed with your merchant credentials:
import jwt
import time
def generate_request_signature(merchant_secret: str, request_data: dict) -> str:
payload = {
"iat": int(time.time()),
"exp": int(time.time()) + 300, # 5 min expiry
"data": request_data
}
return jwt.encode(payload, merchant_secret, algorithm="HS256")
# Use in request
signature = generate_request_signature("your-secret-key", {"merchant_id": "123"})
ucp_checkout_session(..., request_signature=signature)
📚 Available Functions
Core Function
ucp(action, merchant_url, **kwargs)
Generic UCP client supporting all operations.
Actions:
discovery- Get merchant capabilitiescheckout_create- Create checkout sessioncheckout_get- Get checkout sessioncheckout_update- Update checkoutcheckout_complete- Complete checkout with paymentorder_get- Get order detailsorder_list- List ordersorder_cancel- Cancel orderorder_update- Update orderrefund_create- Create refundreturn_create- Create returndispute_create- Create disputecustom- Custom endpoint access
Parameters:
action(str) - UCP action to performmerchant_url(str) - Merchant base URLmethod(str) - HTTP method (auto-set for standard actions)endpoint(str) - Custom endpoint pathheaders(dict) - Additional headersbody(dict) - Request bodycheckout_id(str) - Checkout session IDorder_id(str) - Order IDrequest_signature(str) - Request signature (JWT/token)auto_headers(bool) - Auto-add UCP headers (default: True)timeout(int) - Request timeout in secondsfollow_redirects(bool) - Follow redirects (default: True)
Helper Functions
ucp_discover(merchant_url)
Discover merchant capabilities and services.
ucp_checkout_session(merchant_url, line_items, currency, payment_handlers, buyer=None, request_signature=None)
Create a new checkout session with optional buyer info and signature.
ucp_apply_discount(merchant_url, checkout_id, discount_codes, current_checkout, request_signature=None)
Apply discount codes to checkout with optional signature.
ucp_complete_checkout(merchant_url, checkout_id, payment_instrument, risk_signals=None, request_signature=None)
Complete checkout with payment and optional signature.
🔧 Advanced Usage
Custom Requests
from strands_ucp import ucp
# Custom endpoint with signature
result = ucp(
action="custom",
merchant_url="https://shop.example.com",
method="POST",
endpoint="/api/custom-action",
body={"custom_field": "value"},
request_signature="eyJhbGc..."
)
Manual Header Control
from strands_ucp import ucp
result = ucp(
action="checkout_create",
merchant_url="https://shop.example.com",
body={...},
auto_headers=False, # Disable automatic headers
headers={
"UCP-Agent": 'profile="https://my-agent/profile"',
"request-id": "custom-request-id",
"request-signature": "signed-jwt-token",
"idempotency-key": "custom-idempotency-key"
}
)
Order Management
from strands_ucp import ucp
# Get order
order = ucp(
action="order_get",
merchant_url="https://shop.example.com",
order_id="order_abc123"
)
# Cancel order
ucp(
action="order_cancel",
merchant_url="https://shop.example.com",
order_id="order_abc123",
body={"reason": "Customer request"},
request_signature="eyJhbGc..."
)
# Create refund
ucp(
action="refund_create",
merchant_url="https://shop.example.com",
order_id="order_abc123",
body={"amount": 2500, "reason": "Defective product"},
request_signature="eyJhbGc..."
)
Environment-Based Configuration
# Set signature once for all requests
export UCP_REQUEST_SIGNATURE="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
# Optional: Set custom agent profile
export UCP_AGENT_PROFILE="https://my-company.com/agent-profile"
# Signature automatically loaded from env
from strands_ucp import ucp_checkout_session
checkout = ucp_checkout_session(
merchant_url="https://shop.example.com",
line_items=[...],
currency="USD",
payment_handlers=[...]
# request_signature loaded from UCP_REQUEST_SIGNATURE env var
)
📖 Response Format
All functions return a dictionary with:
{
"status": "success" | "error",
"status_code": 200,
"headers": {...},
"body": {...}, # Parsed JSON response
"ucp_metadata": {...}, # UCP metadata (when available)
"capabilities": [...], # Capabilities (when available)
"checkout_id": "...", # Checkout ID (when available)
"order_id": "...", # Order ID (when available)
"request": {
"method": "POST",
"url": "...",
"headers": {...}, # Note: request-signature excluded from logs
"body": {...}
}
}
Security Note: The request-signature header is excluded from response logs for security.
🧪 Testing
Test with the official UCP sample server:
# Clone samples
git clone https://github.com/Universal-Commerce-Protocol/samples.git
cd samples/rest/python/server
# Install and run
python3 -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt
python server.py --port 8182
Then test:
from strands_ucp import ucp_discover
result = ucp_discover("http://localhost:8182")
print(result)
Testing with Signatures
The sample server may accept test signatures:
from strands_ucp import ucp_checkout_session
checkout = ucp_checkout_session(
merchant_url="http://localhost:8182",
line_items=[{"item": {"id": "test_item"}, "quantity": 1}],
currency="USD",
payment_handlers=[...],
request_signature="test" # Test servers may accept this
)
Production: Always use properly signed JWT tokens in production.
🔗 Protocol Details
Required Headers
Automatically added by the tool (when auto_headers=True):
UCP-Agent- Agent profile identifierrequest-id- Unique request ID (UUID)idempotency-key- For safe retries (POST/PUT/PATCH)request-signature- Request signature (if provided via parameter or env var)
Discovery Endpoint
GET /.well-known/ucp returns:
- UCP version
- Supported services
- Capabilities (checkout, order, discounts, etc.)
- Payment handlers
- Transport bindings (REST, MCP, A2A)
Standard Endpoints
- Checkout:
/checkout-sessions,/checkout-sessions/{id},/checkout-sessions/{id}/complete - Orders:
/orders,/orders/{id},/orders/{id}/cancel - Extensions:
/orders/{id}/refunds,/orders/{id}/returns,/orders/{id}/disputes
🌐 Resources
- UCP Specification: https://ucp.dev
- Python SDK: https://github.com/Universal-Commerce-Protocol/python-sdk
- Samples: https://github.com/Universal-Commerce-Protocol/samples
- Google Integration: https://developers.google.com/merchant/ucp
- Blog Post: https://developers.googleblog.com/under-the-hood-universal-commerce-protocol-ucp/
🤝 Contributing
Contributions welcome! Please:
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests
- Submit a pull request
📄 License
Apache License 2.0 - See LICENSE file for details.
🙏 Acknowledgments
- Built on Strands Agents
- Implements Universal Commerce Protocol (UCP)
Metadata
Release files for strands-ucp 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| strands_ucp-0.1.0.tar.gz | 18.0 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| strands_ucp-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 32.3 kB
Release files / strands_ucp-0.1.0.tar.gz
| Download URL | strands_ucp-0.1.0.tar.gz |
|---|---|
| Size | 18.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
7755fb52c15164408625597418aecdc72c270de7f341826165a1e8a7e885decd
|
|
BLAKE2b-256 checksum How to use checksums |
6f5267605e3908ff2e7cb69f05d0bbd37e607d26441c5e3a296e2504ab52bb0a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Release files / strands_ucp-0.1.0-py3-none-any.whl
| Download URL | strands_ucp-0.1.0-py3-none-any.whl |
|---|---|
| Size | 14.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8d5712fc676b38b6fbd207534f6bd819305f45502239bf4b14658a85c152c723
|
|
BLAKE2b-256 checksum How to use checksums |
fd608dc6ca255fd2078e74d5deec60e773eab8135034d65c2193466f7a8b8794
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.14
|
Security for strands-ucp 0.1.0
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.