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.
Metadata
Release files for pyucp 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pyucp-0.1.2.tar.gz | 12.9 kB | With provenance | Details for pyucp-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pyucp-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for pyucp-0.1.2-py3-none-any.whl |
Total release size: 27.1 kB
Release files / pyucp-0.1.2.tar.gz
| Download URL | pyucp-0.1.2.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
6e544c4b6d5030d6dea8d2ff01501762a1fc5def8fce2f8261af54c631413b22
|
|
BLAKE2b-256 checksum How to use checksums |
1abd1789bb27f7065ac149fd858cbfc31d7bfd833de69551ac673e2cc22dd4fa
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 8, 2026.
Transparency logRelease files / pyucp-0.1.2-py3-none-any.whl
| Download URL | pyucp-0.1.2-py3-none-any.whl |
|---|---|
| Size | 14.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3f43a5c9e6c18c24a75c9b8b1559df74848545ca023cf6ba481f0fd75ed10652
|
|
BLAKE2b-256 checksum How to use checksums |
8753aeac49459b4f5f4cfd9ee5bd030f5eaa4b6c37c3e46594ded3bad4d00258
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 8, 2026.
Transparency logSecurity for pyucp 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for pyucp-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Jul 8, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.