-
Notifications
You must be signed in to change notification settings - Fork 40
docs: improve README with PyPI install, usage examples, and badges #27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
pjordan
wants to merge
2
commits into
Universal-Commerce-Protocol:main
Choose a base branch
from
pjordan:worktree-docs+improve-readme
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+68
−8
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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 | ||
|
|
@@ -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`: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
|
||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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:
[...]