Skip to content
Merged
Show file tree
Hide file tree
Changes from 20 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
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,7 @@ For now, you can install the SDK using the following commands:
mkdir sdk

# Clone the repository
git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git sdk/python

# Navigate to the directory
cd sdk/python
git clone https://github.com/Universal-Commerce-Protocol/python-sdk.git

# Install dependencies
uv sync
Expand All @@ -62,9 +59,13 @@ To regenerate the models:

```bash
uv sync
./generate_models.sh
./generate_models.sh <version>
```

Where `<version>` is the version of the UCP specification to use (for example, "2026-01-23").

If no version is specified, the `main` branch of the [UCP repo](https://github.com/Universal-Commerce-Protocol/ucp) will be used.

The generated code is automatically formatted using `ruff`.

## Contributing
Expand Down
36 changes: 32 additions & 4 deletions generate_models.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,35 @@
# Ensure we are in the script's directory
cd "$(dirname "$0")" || exit

# Check if git is installed
if ! command -v git &> /dev/null; then
echo "Error: git not found. Please install git."
exit 1
fi

# UCP Version to use (if provided, use release/$1 branch; otherwise, use main)
if [ -z "$1" ]; then
BRANCH="main"
echo "No version specified, cloning main branch..."
else
BRANCH="release/$1"
echo "Cloning version $1 (branch: $BRANCH)..."
fi

# Ensure ucp directory is clean before cloning
rm -rf ucp
git clone -b "$BRANCH" --depth 1 https://github.com/Universal-Commerce-Protocol/ucp ucp

# Output directory
OUTPUT_DIR="src/ucp_sdk/models"

# Schema directory (relative to this script)
SCHEMA_DIR="../../spec/"
SCHEMA_DIR="ucp/source"

echo "Preprocessing schemas..."
# uv run python preprocess_schemas.py

echo "Generating Pydantic models from $SCHEMA_DIR..."
echo "Generating Pydantic models from preprocessed schemas..."

# Check if uv is installed
if ! command -v uv &> /dev/null; then
Expand All @@ -23,9 +45,11 @@ fi
rm -r -f "$OUTPUT_DIR"
mkdir -p "$OUTPUT_DIR"


# Run generation using uv
# We use --use-schema-description to use descriptions from JSON schema as docstrings
# We use --field-constraints to include validation constraints (regex, min/max, etc.)
# Note: Formatting is done as a post-processing step.
uv run \
--link-mode=copy \
--extra-index-url https://pypi.org/simple python \
Expand All @@ -41,7 +65,11 @@ uv run \
--disable-timestamp \
--use-double-quotes \
--no-use-annotated \
--allow-extra-fields \
--formatters ruff-format ruff-check
--allow-extra-fields

echo "Formatting generated models..."
uv run ruff format
uv run ruff check --fix "$OUTPUT_DIR" 2>&1 | grep -E "^(All checks passed|Fixed|Found)" || echo "Formatting complete"


echo "Done. Models generated in $OUTPUT_DIR"
28 changes: 13 additions & 15 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
[project]
name = "ucp-sdk"
version = "0.1.0"
version = "2026.01.23"
description = "UCP Python SDK"
readme = "README.md"
license-files = ["LICENSE"]
authors = [
{ name = "Florin Iucha", email = "[email protected]" }
{ name = "Florin Iucha", email = "[email protected]" },
{ name = "Federico D'Amato", email = "[email protected]" },
]
requires-python = ">=3.10"
dependencies = [
Expand Down Expand Up @@ -47,19 +49,15 @@ custom-file-header = """

[tool.ruff]
line-length = 80
indent-width = 2

[tool.ruff.format]
quote-style = "double"
indent-style = "space"
skip-magic-trailing-comma = false
line-ending = "auto"
docstring-code-format = true
target-version = "py311"

[tool.ruff.lint]
select = ["E", "F", "W", "B", "C4", "SIM", "N", "UP", "D", "PTH", "T20"]
select = ["E", "F", "I"]
ignore = ["E501"]

[tool.ruff.lint.pydocstyle]
convention = "google"

[tool.ruff.lint.isort]
combine-as-imports = true
force-sort-within-sections = true
case-sensitive = true
[tool.ruff.lint.per-file-ignores]
"__init__.py" = ["D104"]
"*.py" = ["D100", "D101", "D102", "D103", "D200", "D205", "D212"]
19 changes: 0 additions & 19 deletions src/ucp_sdk/__init__.py

This file was deleted.

1 change: 1 addition & 0 deletions src/ucp_sdk/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# generated by datamodel-codegen
# pylint: disable=all
# pyformat: disable

227 changes: 0 additions & 227 deletions src/ucp_sdk/models/_internal.py

This file was deleted.

1 change: 1 addition & 0 deletions src/ucp_sdk/models/discovery/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@
# generated by datamodel-codegen
# pylint: disable=all
# pyformat: disable

Loading
Loading