Universal Context Package (UCP) — reference library: validation, typed models, canonical LLM rendering
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyucp-0.1.0.tar.gz.
File metadata
- Download URL: pyucp-0.1.0.tar.gz
- Upload date:
- Size: 10.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
61b80bb71dc0f844ec417abf9577dec5d886748876f44e630dccf60a35ca5cf5
|
|
| MD5 |
77af0b213180de640a35b956c38e0959
|
|
| BLAKE2b-256 |
06027f6e2fba9af41915574e456741925e6954bf99b81cd44b7cee07a9970c13
|
Provenance
The following attestation bundles were made for pyucp-0.1.0.tar.gz:
Publisher:
release.yml on ucpcore/ucp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyucp-0.1.0.tar.gz -
Subject digest:
61b80bb71dc0f844ec417abf9577dec5d886748876f44e630dccf60a35ca5cf5 - Sigstore transparency entry: 2082465425
- Sigstore integration time:
-
Permalink:
ucpcore/ucp@2c2143e05cbe1b9aa175dab52f71d92fb8a26f48 -
Branch / Tag:
refs/tags/py-v0.1.0 - Owner: https://github.com/ucpcore
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2c2143e05cbe1b9aa175dab52f71d92fb8a26f48 -
Trigger Event:
push
-
Statement type:
File details
Details for the file pyucp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pyucp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 10.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6544b14495f99eef07037327b81a929e540801830bb826f718ce078bfcbb5943
|
|
| MD5 |
f54b62cfd3b524e33024623bb4e40684
|
|
| BLAKE2b-256 |
a5b552a3dc6a1aff470f10efe88db6ac80dd6633b68fa1ec5c70c4fe3104ec96
|
Provenance
The following attestation bundles were made for pyucp-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ucpcore/ucp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyucp-0.1.0-py3-none-any.whl -
Subject digest:
6544b14495f99eef07037327b81a929e540801830bb826f718ce078bfcbb5943 - Sigstore transparency entry: 2082465430
- Sigstore integration time:
-
Permalink:
ucpcore/ucp@2c2143e05cbe1b9aa175dab52f71d92fb8a26f48 -
Branch / Tag:
refs/tags/py-v0.1.0 - Owner: https://github.com/ucpcore
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@2c2143e05cbe1b9aa175dab52f71d92fb8a26f48 -
Trigger Event:
push
-
Statement type: