2222 <b >Official Python library for the Universal Commerce Protocol (UCP).</b >
2323</p >
2424
25+ <p align =" center " >
26+ <a href =" https://pypi.org/project/ucp-sdk/ " ><img src =" https://img.shields.io/pypi/v/ucp-sdk " alt =" PyPI version " ></a >
27+ <a href =" https://pypi.org/project/ucp-sdk/ " ><img src =" https://img.shields.io/pypi/pyversions/ucp-sdk " alt =" Python versions " ></a >
28+ <a href =" https://github.com/Universal-Commerce-Protocol/python-sdk/blob/main/LICENSE " ><img src =" https://img.shields.io/github/license/Universal-Commerce-Protocol/python-sdk " alt =" License " ></a >
29+ </p >
30+
2531## Overview
2632
2733This repository contains the Python SDK for the
@@ -31,24 +37,80 @@ Python.
3137
3238## Installation
3339
34- For now, you can install the SDK using the following commands :
40+ Install from PyPI :
3541
3642``` bash
37- # Clone the repository
38- git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git
43+ pip install ucp-sdk
44+ ```
3945
40- # Navigate to the directory
41- cd python-sdk
46+ Or with [ uv] ( https://docs.astral.sh/uv/ ) :
4247
43- # Install dependencies
44- uv sync
48+ ``` bash
49+ uv add ucp-sdk
50+ ```
51+
52+ ## Usage
53+
54+ The SDK provides typed [ Pydantic v2] ( https://docs.pydantic.dev/ ) models for all
55+ UCP schemas. Import models from ` ucp_sdk.models.schemas ` :
56+
57+ ``` python
58+ from ucp_sdk.models.schemas.shopping.checkout import Checkout
59+ from ucp_sdk.models.schemas.shopping.types.line_item import LineItem
60+ from ucp_sdk.models.schemas.shopping.types.total import Total
61+
62+ # Parse a UCP checkout response
63+ checkout = Checkout.model_validate(checkout_data)
64+
65+ # Access typed fields
66+ print (checkout.status) # "incomplete" | "ready_for_complete" | ...
67+ print (checkout.currency) # ISO 4217 currency code
68+ for item in checkout.line_items:
69+ print (f " { item.item.title} : { item.quantity} " )
70+ ```
71+
72+ ### Available model packages
73+
74+ | Package | Description |
75+ | ---------| -------------|
76+ | ` ucp_sdk.models.schemas.shopping ` | Checkout, cart, order, payment models |
77+ | ` ucp_sdk.models.schemas.shopping.types ` | Line items, totals, buyer, fulfillment, etc. |
78+ | ` ucp_sdk.models.schemas.transports ` | REST, MCP, and embedded protocol bindings |
79+ | ` ucp_sdk.models.schemas ` | Service definitions, capabilities, payment handlers |
80+
81+ ### Validation
82+
83+ All models support Pydantic validation and serialization:
84+
85+ ``` python
86+ from pydantic import ValidationError
87+
88+ # Validate data against UCP schemas
89+ try :
90+ checkout = Checkout.model_validate(data)
91+ except ValidationError as e:
92+ print (e.errors())
93+
94+ # Serialize to JSON-compatible dict
95+ checkout_dict = checkout.model_dump(exclude_none = True )
4596```
4697
4798## Development
4899
49100### Prerequisites
50101
51- This project uses ` uv ` for dependency management.
102+ This project uses [ ` uv ` ] ( https://docs.astral.sh/uv/ ) for dependency management.
103+
104+ ### Setup
105+
106+ ``` bash
107+ # Clone the repository
108+ git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git
109+ cd python-sdk
110+
111+ # Install dependencies
112+ uv sync
113+ ```
52114
53115### Generating Pydantic Models
54116
0 commit comments