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,77 @@ Python.
3137
3238## Installation
3339
34- For now, you can install the SDK using the following commands :
40+ To use this SDK in your own project, install it 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, if you are managing your project 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 example below parses a UCP checkout response and reads typed fields:
55+
56+ ``` python
57+ from ucp_sdk.models.schemas.shopping.checkout import Checkout
58+
59+ # Parse a UCP checkout response
60+ checkout = Checkout.model_validate(checkout_data)
61+
62+ # Access typed fields
63+ print (checkout.status) # "incomplete" | "ready_for_complete" | ...
64+ print (checkout.currency) # ISO 4217 currency code
65+ for item in checkout.line_items:
66+ print (f " { item.item.title} : { item.quantity} " )
67+ ```
68+
69+ ### Available model packages
70+
71+ | Package | Description |
72+ | --------------------------------------- | --------------------------------------------------- |
73+ | ` ucp_sdk.models.schemas.shopping ` | Checkout, cart, order, payment models |
74+ | ` ucp_sdk.models.schemas.shopping.types ` | Line items, totals, buyer, fulfillment, etc. |
75+ | ` ucp_sdk.models.schemas.transports ` | REST, MCP, and embedded protocol bindings |
76+ | ` ucp_sdk.models.schemas ` | Service definitions, capabilities, payment handlers |
77+
78+ ### Validation
79+
80+ All models support Pydantic validation and serialization:
81+
82+ ``` python
83+ from pydantic import ValidationError
84+ from ucp_sdk.models.schemas.shopping.checkout import Checkout
85+
86+ # Validate data against UCP schemas
87+ try :
88+ checkout = Checkout.model_validate(checkout_data)
89+ # Serialize to JSON-compatible dict
90+ checkout_dict = checkout.model_dump(exclude_none = True )
91+ except ValidationError as e:
92+ print (e.errors())
4593```
4694
4795## Development
4896
4997### Prerequisites
5098
51- This project uses ` uv ` for dependency management.
99+ This project uses [ ` uv ` ] ( https://docs.astral.sh/uv/ ) for dependency management.
100+
101+ ### Setup
102+
103+ ``` bash
104+ # Clone the repository
105+ git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git
106+ cd python-sdk
107+
108+ # Install dependencies
109+ uv sync
110+ ```
52111
53112### Generating Pydantic Models
54113
0 commit comments