Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
76 changes: 68 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
<b>Official Python library for the Universal Commerce Protocol (UCP).</b>
</p>

<p align="center">
<a href="https://pypi.org/project/ucp-sdk/"><img src="https://img.shields.io/pypi/v/ucp-sdk" alt="PyPI version"></a>
<a href="https://pypi.org/project/ucp-sdk/"><img src="https://img.shields.io/pypi/pyversions/ucp-sdk" alt="Python versions"></a>
<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>
</p>

## Overview

This repository contains the Python SDK for the
Expand All @@ -31,24 +37,78 @@ Python.

## Installation

For now, you can install the SDK using the following commands:
Install from PyPI:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: Could you clarify this is installation on another project? For example: "To use this SDK in your own project, install it from PyPI:"

[...]

Or, if you are managing your project with uv:
[...]


```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`:
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is already mentioned in 34:35. Is it also needed here?


```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

Expand Down
Loading