diff --git a/README.md b/README.md index 810a977..01c0920 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,12 @@ Official Python library for the Universal Commerce Protocol (UCP).
+ + ## Overview This repository contains the Python SDK for the @@ -31,24 +37,78 @@ Python. ## Installation -For now, you can install the SDK using the following commands: +Install from PyPI: ```bash -# Clone the repository -git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git +pip install ucp-sdk +``` -# Navigate to the directory -cd python-sdk +Or with [uv](https://docs.astral.sh/uv/): -# Install dependencies -uv sync +```bash +uv add ucp-sdk +``` + +## Usage + +The SDK provides typed [Pydantic v2](https://docs.pydantic.dev/) models for all +UCP schemas. Import models from `ucp_sdk.models.schemas`: + +```python +from ucp_sdk.models.schemas.shopping.checkout import Checkout + +# Parse a UCP checkout response +checkout = Checkout.model_validate(checkout_data) + +# Access typed fields +print(checkout.status) # "incomplete" | "ready_for_complete" | ... +print(checkout.currency) # ISO 4217 currency code +for item in checkout.line_items: + print(f"{item.item.title}: {item.quantity}") +``` + +### Available model packages + +| Package | Description | +|---------|-------------| +| `ucp_sdk.models.schemas.shopping` | Checkout, cart, order, payment models | +| `ucp_sdk.models.schemas.shopping.types` | Line items, totals, buyer, fulfillment, etc. | +| `ucp_sdk.models.schemas.transports` | REST, MCP, and embedded protocol bindings | +| `ucp_sdk.models.schemas` | Service definitions, capabilities, payment handlers | + +### Validation + +All models support Pydantic validation and serialization: + +```python +from pydantic import ValidationError +from ucp_sdk.models.schemas.shopping.checkout import Checkout + +# Validate data against UCP schemas +try: + checkout = Checkout.model_validate(data) + # Serialize to JSON-compatible dict + checkout_dict = checkout.model_dump(exclude_none=True) +except ValidationError as e: + print(e.errors()) ``` ## Development ### Prerequisites -This project uses `uv` for dependency management. +This project uses [`uv`](https://docs.astral.sh/uv/) for dependency management. + +### Setup + +```bash +# Clone the repository +git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git +cd python-sdk + +# Install dependencies +uv sync +``` ### Generating Pydantic Models