Skip to main content

ucp — Universal Context Package reference library (Python)

Reference implementation of the UCP specification (v0.1.0-draft): schema validation, typed Pydantic models, and canonical CommonMark rendering for LLM prompts with token budgeting.

pip install pyucp   # distribution "pyucp", import name "ucp"

Quickstart

import ucp

# Load and validate a package (raises ucp.UCPValidationError on failure)
pkg = ucp.load("task.ucp.json")

print(pkg.entity.title)
print(pkg.must_know[0].text)

# Canonical prompt rendering (SPEC §7.1)
prompt = ucp.render(pkg)

# Under a token budget: truncates by ascending salience, drops sections
# in the order defined by SPEC §7.2 (summary/conflicts/diff survive longest)
prompt = ucp.render(pkg, token_budget=1500)

# Validation without parsing into models
errors = ucp.iter_errors({"ucp_version": "0.1.0"})  # -> list of messages

# Referential integrity (ucp-core profile): every claim source key must exist
dangling = pkg.verify_references()  # -> [] when clean

What this library guarantees

  • Schema validation against the bundled JSON Schema (draft 2020-12), identical to specs/ucp/schema/ucp.schema.json.
  • Must-ignore semantics: unknown fields are preserved, never rejected (SPEC §6.1) — models use extra="allow".
  • Provenance enforcement: a claim without sources fails both schema validation and model parsing.
  • Deterministic rendering: the same package always renders to the same prompt, so downstream LLM behavior is reproducible.

Token counting uses a fast len(text) / 4 heuristic; pass your own counter via render(pkg, token_budget=..., count_tokens=fn) for exact budgets.

Development

pip install -e ".[dev]"
pytest

Tests run against the spec's examples/ and conformance/ suites when the repository layout is available.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyucp-0.1.1.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pyucp-0.1.1-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

File details

Details for the file pyucp-0.1.1.tar.gz.

File metadata

  • Download URL: pyucp-0.1.1.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyucp-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0f1679bd710f7e1bfed32d8a5252211c68dd87f24c2c86a012755948cbd0e3b1
MD5 cb8d644f8ded137e7c1104eb0cfdacee
BLAKE2b-256 7b1dfd0c7e874481dcd572cfdde766372fbdc2a1f9578bc314b68926aa11ec38

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyucp-0.1.1.tar.gz:

Publisher: release.yml on ucpcore/ucp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyucp-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pyucp-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for pyucp-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 fa5ea09883640c6afff87ac9c92bef5541ec12d7d6e732ee38a93c88346718f6
MD5 9c6a4bb9d8435a4274252e7bfbcec18b
BLAKE2b-256 32013bc5256e894ece80987c5c97edd809919d48cf12f127c9450270095bbb8d

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyucp-0.1.1-py3-none-any.whl:

Publisher: release.yml on ucpcore/ucp

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page