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.2.tar.gz (12.9 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.2-py3-none-any.whl (14.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: pyucp-0.1.2.tar.gz
  • Upload date:
  • Size: 12.9 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.2.tar.gz
Algorithm Hash digest
SHA256 6e544c4b6d5030d6dea8d2ff01501762a1fc5def8fce2f8261af54c631413b22
MD5 36e56fa15410b1f26ff091d189e13b31
BLAKE2b-256 1abd1789bb27f7065ac149fd858cbfc31d7bfd833de69551ac673e2cc22dd4fa

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyucp-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: pyucp-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 14.2 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 3f43a5c9e6c18c24a75c9b8b1559df74848545ca023cf6ba481f0fd75ed10652
MD5 eb4a57592826f6fec92bde2ad604d820
BLAKE2b-256 8753aeac49459b4f5f4cfd9ee5bd030f5eaa4b6c37c3e46594ded3bad4d00258

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyucp-0.1.2-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