Skip to main content

Python reference implementation of the Universal Personalization Protocol (UPP) data models

Project description

UPP Python — Reference Implementation

Python reference implementation of the Universal Personalization Protocol (UPP) data models, backends, and client.

Installation

pip install upp-python

Development

pip install -e ".[dev]"

Quick Start

from upp import Event, StoredEvent, SourceType, EventStatus
from upp import LabelDefinition, OntologyUserV1, UPPClient

# Create an event (pre-storage)
event = Event(
    value="I work as a senior software engineer at Anthropic",
    labels=["what_occupation"],
    confidence=0.95,
    source_type=SourceType.USER_STATED,
)

# Use with a client (requires backend implementations)
import asyncio

async def demo():
    client = UPPClient(
        ingest=my_ingest_backend,
        retriever=my_retriever_backend,
        ontology=OntologyUserV1(),
    )
    stored = await client.ingest("user-123", [event])
    print(f"Stored: {stored[0].value} (id={stored[0].id})")

    # Retrieve events
    events = await client.get_events("user-123")
    print(f"Total events: {len(events)}")

asyncio.run(demo())

Package Structure

src/upp/
├── __init__.py              # Top-level exports
├── client.py                # UPPClient — high-level protocol client
├── models/
│   ├── __init__.py           # Model re-exports
│   ├── client.py             # UPPClientProtocol
│   ├── enums.py              # EventStatus, SourceType, SensitivityTier, Cardinality, Durability
│   ├── events.py             # Event, StoredEvent
│   └── labels.py             # LabelDefinition
├── backends/
│   ├── __init__.py           # Backend re-exports
│   ├── ingest.py             # IngestBackend protocol
│   ├── retriever.py          # RetrieverBackend protocol
│   └── ontology.py           # OntologyBackend protocol
├── ontologies/
│   ├── __init__.py
│   └── user_v1.py            # OntologyUserV1 — loads ontologies/user/v1.json
└── rpc/
    ├── __init__.py           # RPC re-exports
    ├── methods.py            # UPP_INGEST, UPP_RETRIEVE, etc.
    ├── errors.py             # Error codes and UppError
    ├── messages.py           # JSON-RPC types + operation request/response models
    └── codec.py              # JSON-RPC encode/decode

Protocol Operations

The UPP protocol defines 8 operations:

Operation Type Description
upp/ingest Core (write) Extract and ingest events from text
upp/retrieve Core (read) Intelligent retrieval of relevant events
upp/events Core (read) List all stored events
upp/delete Core (write) Delete events (GDPR compliance)
upp/info Discovery Server metadata
upp/labels Discovery Label definitions from an ontology
upp/export Portability Export events for migration
upp/import Portability Import events from another server

Requirements

  • Python >= 3.11
  • Pydantic >= 2.0.0

Testing

pytest tests/ -v

License

MIT — See LICENSE for details.

Project details


Download files

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

Source Distribution

upp_python-0.1.0.tar.gz (62.6 kB view details)

Uploaded Source

Built Distribution

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

upp_python-0.1.0-py3-none-any.whl (23.6 kB view details)

Uploaded Python 3

File details

Details for the file upp_python-0.1.0.tar.gz.

File metadata

  • Download URL: upp_python-0.1.0.tar.gz
  • Upload date:
  • Size: 62.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for upp_python-0.1.0.tar.gz
Algorithm Hash digest
SHA256 b12e65988686a89bae40250588e1b941bee4b0b97c069917904be5208bea1143
MD5 ee4ef943e23acf535427c11716ef4f42
BLAKE2b-256 7ed4baadef8c186dc6f950eb5de2cc235c2ee3a5f4773933a5537c1e37a992fb

See more details on using hashes here.

Provenance

The following attestation bundles were made for upp_python-0.1.0.tar.gz:

Publisher: publish-python.yml on Contextually-AI/upp

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

File details

Details for the file upp_python-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: upp_python-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 23.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for upp_python-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fb1af6e4e62f010ec8b5218d15cee88b0034e61ec8263f61f5aee94faca4de3e
MD5 e2fc04008e06d53212bb61d19b3a1c9b
BLAKE2b-256 5d2161db963b42da9be3d2a06475adf58cce3dfc91f7bac89e5141b5857119e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for upp_python-0.1.0-py3-none-any.whl:

Publisher: publish-python.yml on Contextually-AI/upp

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 Pingdom Monitoring Sentry Error logging StatusPage Status page