upp-python 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- upp_python-0.1.0/.gitignore +42 -0
- upp_python-0.1.0/PKG-INFO +137 -0
- upp_python-0.1.0/README.md +106 -0
- upp_python-0.1.0/pyproject.toml +65 -0
- upp_python-0.1.0/src/upp/__init__.py +183 -0
- upp_python-0.1.0/src/upp/backends/.gitkeep +0 -0
- upp_python-0.1.0/src/upp/backends/__init__.py +23 -0
- upp_python-0.1.0/src/upp/backends/ingest.py +122 -0
- upp_python-0.1.0/src/upp/backends/ontology.py +41 -0
- upp_python-0.1.0/src/upp/backends/retriever.py +79 -0
- upp_python-0.1.0/src/upp/client.py +148 -0
- upp_python-0.1.0/src/upp/models/.gitkeep +0 -0
- upp_python-0.1.0/src/upp/models/__init__.py +38 -0
- upp_python-0.1.0/src/upp/models/client.py +113 -0
- upp_python-0.1.0/src/upp/models/enums.py +124 -0
- upp_python-0.1.0/src/upp/models/events.py +124 -0
- upp_python-0.1.0/src/upp/models/labels.py +71 -0
- upp_python-0.1.0/src/upp/ontologies/__init__.py +0 -0
- upp_python-0.1.0/src/upp/ontologies/user_v1.py +112 -0
- upp_python-0.1.0/src/upp/py.typed +0 -0
- upp_python-0.1.0/src/upp/rpc/.gitkeep +0 -0
- upp_python-0.1.0/src/upp/rpc/__init__.py +137 -0
- upp_python-0.1.0/src/upp/rpc/codec.py +112 -0
- upp_python-0.1.0/src/upp/rpc/errors.py +127 -0
- upp_python-0.1.0/src/upp/rpc/messages.py +354 -0
- upp_python-0.1.0/src/upp/rpc/methods.py +73 -0
- upp_python-0.1.0/test-suite.sh +15 -0
- upp_python-0.1.0/tests/.gitkeep +0 -0
- upp_python-0.1.0/tests/conftest.py +118 -0
- upp_python-0.1.0/tests/test_backends.py +119 -0
- upp_python-0.1.0/tests/test_client.py +276 -0
- upp_python-0.1.0/tests/test_default_ontology.py +152 -0
- upp_python-0.1.0/tests/test_memory_store.py +6 -0
- upp_python-0.1.0/tests/test_models.py +570 -0
- upp_python-0.1.0/tests/test_rpc.py +449 -0
- upp_python-0.1.0/uv.lock +574 -0
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# Python
|
|
2
|
+
__pycache__/
|
|
3
|
+
*.py[cod]
|
|
4
|
+
*$py.class
|
|
5
|
+
*.egg-info/
|
|
6
|
+
dist/
|
|
7
|
+
build/
|
|
8
|
+
.venv/
|
|
9
|
+
venv/
|
|
10
|
+
*.egg
|
|
11
|
+
.coverage
|
|
12
|
+
.coverage.*
|
|
13
|
+
coverage/
|
|
14
|
+
htmlcov/
|
|
15
|
+
|
|
16
|
+
# Environment
|
|
17
|
+
.env
|
|
18
|
+
.env.local
|
|
19
|
+
.env.*
|
|
20
|
+
|
|
21
|
+
# Native extensions
|
|
22
|
+
*.so
|
|
23
|
+
*.pyd
|
|
24
|
+
|
|
25
|
+
# TypeScript / Node
|
|
26
|
+
node_modules/
|
|
27
|
+
*.js
|
|
28
|
+
*.d.ts
|
|
29
|
+
*.js.map
|
|
30
|
+
!jest.config.js
|
|
31
|
+
!vitest.config.ts
|
|
32
|
+
!eslint.config.js
|
|
33
|
+
|
|
34
|
+
# IDE
|
|
35
|
+
.idea/
|
|
36
|
+
.vscode/
|
|
37
|
+
*.swp
|
|
38
|
+
*.swo
|
|
39
|
+
|
|
40
|
+
# OS
|
|
41
|
+
.DS_Store
|
|
42
|
+
Thumbs.db
|
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: upp-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Python reference implementation of the Universal Personalization Protocol (UPP) data models
|
|
5
|
+
Project-URL: Homepage, https://github.com/Contextually-AI/upp
|
|
6
|
+
Project-URL: Documentation, https://github.com/Contextually-AI/upp/tree/main/spec
|
|
7
|
+
Project-URL: Repository, https://github.com/Contextually-AI/upp
|
|
8
|
+
Project-URL: Issues, https://github.com/Contextually-AI/upp/issues
|
|
9
|
+
Project-URL: Changelog, https://github.com/Contextually-AI/upp/blob/main/CHANGELOG.md
|
|
10
|
+
Author: UPP Protocol Authors
|
|
11
|
+
License-Expression: MIT
|
|
12
|
+
Keywords: json-rpc,personalization,protocol,pydantic,user-profile
|
|
13
|
+
Classifier: Development Status :: 4 - Beta
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Requires-Python: >=3.11
|
|
23
|
+
Requires-Dist: pydantic>=2.0.0
|
|
24
|
+
Provides-Extra: dev
|
|
25
|
+
Requires-Dist: mypy; extra == 'dev'
|
|
26
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == 'dev'
|
|
27
|
+
Requires-Dist: pytest-cov; extra == 'dev'
|
|
28
|
+
Requires-Dist: pytest>=8.0.0; extra == 'dev'
|
|
29
|
+
Requires-Dist: ruff; extra == 'dev'
|
|
30
|
+
Description-Content-Type: text/markdown
|
|
31
|
+
|
|
32
|
+
# UPP Python — Reference Implementation
|
|
33
|
+
|
|
34
|
+
Python reference implementation of the [Universal Personalization Protocol (UPP)](../../spec/01-overview.md) data models, backends, and client.
|
|
35
|
+
|
|
36
|
+
## Installation
|
|
37
|
+
|
|
38
|
+
```bash
|
|
39
|
+
pip install upp-python
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### Development
|
|
43
|
+
|
|
44
|
+
```bash
|
|
45
|
+
pip install -e ".[dev]"
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
## Quick Start
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
from upp import Event, StoredEvent, SourceType, EventStatus
|
|
52
|
+
from upp import LabelDefinition, OntologyUserV1, UPPClient
|
|
53
|
+
|
|
54
|
+
# Create an event (pre-storage)
|
|
55
|
+
event = Event(
|
|
56
|
+
value="I work as a senior software engineer at Anthropic",
|
|
57
|
+
labels=["what_occupation"],
|
|
58
|
+
confidence=0.95,
|
|
59
|
+
source_type=SourceType.USER_STATED,
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
# Use with a client (requires backend implementations)
|
|
63
|
+
import asyncio
|
|
64
|
+
|
|
65
|
+
async def demo():
|
|
66
|
+
client = UPPClient(
|
|
67
|
+
ingest=my_ingest_backend,
|
|
68
|
+
retriever=my_retriever_backend,
|
|
69
|
+
ontology=OntologyUserV1(),
|
|
70
|
+
)
|
|
71
|
+
stored = await client.ingest("user-123", [event])
|
|
72
|
+
print(f"Stored: {stored[0].value} (id={stored[0].id})")
|
|
73
|
+
|
|
74
|
+
# Retrieve events
|
|
75
|
+
events = await client.get_events("user-123")
|
|
76
|
+
print(f"Total events: {len(events)}")
|
|
77
|
+
|
|
78
|
+
asyncio.run(demo())
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## Package Structure
|
|
82
|
+
|
|
83
|
+
```
|
|
84
|
+
src/upp/
|
|
85
|
+
├── __init__.py # Top-level exports
|
|
86
|
+
├── client.py # UPPClient — high-level protocol client
|
|
87
|
+
├── models/
|
|
88
|
+
│ ├── __init__.py # Model re-exports
|
|
89
|
+
│ ├── client.py # UPPClientProtocol
|
|
90
|
+
│ ├── enums.py # EventStatus, SourceType, SensitivityTier, Cardinality, Durability
|
|
91
|
+
│ ├── events.py # Event, StoredEvent
|
|
92
|
+
│ └── labels.py # LabelDefinition
|
|
93
|
+
├── backends/
|
|
94
|
+
│ ├── __init__.py # Backend re-exports
|
|
95
|
+
│ ├── ingest.py # IngestBackend protocol
|
|
96
|
+
│ ├── retriever.py # RetrieverBackend protocol
|
|
97
|
+
│ └── ontology.py # OntologyBackend protocol
|
|
98
|
+
├── ontologies/
|
|
99
|
+
│ ├── __init__.py
|
|
100
|
+
│ └── user_v1.py # OntologyUserV1 — loads ontologies/user/v1.json
|
|
101
|
+
└── rpc/
|
|
102
|
+
├── __init__.py # RPC re-exports
|
|
103
|
+
├── methods.py # UPP_INGEST, UPP_RETRIEVE, etc.
|
|
104
|
+
├── errors.py # Error codes and UppError
|
|
105
|
+
├── messages.py # JSON-RPC types + operation request/response models
|
|
106
|
+
└── codec.py # JSON-RPC encode/decode
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Protocol Operations
|
|
110
|
+
|
|
111
|
+
The UPP protocol defines 8 operations:
|
|
112
|
+
|
|
113
|
+
| Operation | Type | Description |
|
|
114
|
+
|---|---|---|
|
|
115
|
+
| `upp/ingest` | Core (write) | Extract and ingest events from text |
|
|
116
|
+
| `upp/retrieve` | Core (read) | Intelligent retrieval of relevant events |
|
|
117
|
+
| `upp/events` | Core (read) | List all stored events |
|
|
118
|
+
| `upp/delete` | Core (write) | Delete events (GDPR compliance) |
|
|
119
|
+
| `upp/info` | Discovery | Server metadata |
|
|
120
|
+
| `upp/labels` | Discovery | Label definitions from an ontology |
|
|
121
|
+
| `upp/export` | Portability | Export events for migration |
|
|
122
|
+
| `upp/import` | Portability | Import events from another server |
|
|
123
|
+
|
|
124
|
+
## Requirements
|
|
125
|
+
|
|
126
|
+
- Python >= 3.11
|
|
127
|
+
- Pydantic >= 2.0.0
|
|
128
|
+
|
|
129
|
+
## Testing
|
|
130
|
+
|
|
131
|
+
```bash
|
|
132
|
+
pytest tests/ -v
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
MIT — See [LICENSE](../../LICENSE) for details.
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
# UPP Python — Reference Implementation
|
|
2
|
+
|
|
3
|
+
Python reference implementation of the [Universal Personalization Protocol (UPP)](../../spec/01-overview.md) data models, backends, and client.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install upp-python
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
### Development
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install -e ".[dev]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
from upp import Event, StoredEvent, SourceType, EventStatus
|
|
21
|
+
from upp import LabelDefinition, OntologyUserV1, UPPClient
|
|
22
|
+
|
|
23
|
+
# Create an event (pre-storage)
|
|
24
|
+
event = Event(
|
|
25
|
+
value="I work as a senior software engineer at Anthropic",
|
|
26
|
+
labels=["what_occupation"],
|
|
27
|
+
confidence=0.95,
|
|
28
|
+
source_type=SourceType.USER_STATED,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# Use with a client (requires backend implementations)
|
|
32
|
+
import asyncio
|
|
33
|
+
|
|
34
|
+
async def demo():
|
|
35
|
+
client = UPPClient(
|
|
36
|
+
ingest=my_ingest_backend,
|
|
37
|
+
retriever=my_retriever_backend,
|
|
38
|
+
ontology=OntologyUserV1(),
|
|
39
|
+
)
|
|
40
|
+
stored = await client.ingest("user-123", [event])
|
|
41
|
+
print(f"Stored: {stored[0].value} (id={stored[0].id})")
|
|
42
|
+
|
|
43
|
+
# Retrieve events
|
|
44
|
+
events = await client.get_events("user-123")
|
|
45
|
+
print(f"Total events: {len(events)}")
|
|
46
|
+
|
|
47
|
+
asyncio.run(demo())
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## Package Structure
|
|
51
|
+
|
|
52
|
+
```
|
|
53
|
+
src/upp/
|
|
54
|
+
├── __init__.py # Top-level exports
|
|
55
|
+
├── client.py # UPPClient — high-level protocol client
|
|
56
|
+
├── models/
|
|
57
|
+
│ ├── __init__.py # Model re-exports
|
|
58
|
+
│ ├── client.py # UPPClientProtocol
|
|
59
|
+
│ ├── enums.py # EventStatus, SourceType, SensitivityTier, Cardinality, Durability
|
|
60
|
+
│ ├── events.py # Event, StoredEvent
|
|
61
|
+
│ └── labels.py # LabelDefinition
|
|
62
|
+
├── backends/
|
|
63
|
+
│ ├── __init__.py # Backend re-exports
|
|
64
|
+
│ ├── ingest.py # IngestBackend protocol
|
|
65
|
+
│ ├── retriever.py # RetrieverBackend protocol
|
|
66
|
+
│ └── ontology.py # OntologyBackend protocol
|
|
67
|
+
├── ontologies/
|
|
68
|
+
│ ├── __init__.py
|
|
69
|
+
│ └── user_v1.py # OntologyUserV1 — loads ontologies/user/v1.json
|
|
70
|
+
└── rpc/
|
|
71
|
+
├── __init__.py # RPC re-exports
|
|
72
|
+
├── methods.py # UPP_INGEST, UPP_RETRIEVE, etc.
|
|
73
|
+
├── errors.py # Error codes and UppError
|
|
74
|
+
├── messages.py # JSON-RPC types + operation request/response models
|
|
75
|
+
└── codec.py # JSON-RPC encode/decode
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
## Protocol Operations
|
|
79
|
+
|
|
80
|
+
The UPP protocol defines 8 operations:
|
|
81
|
+
|
|
82
|
+
| Operation | Type | Description |
|
|
83
|
+
|---|---|---|
|
|
84
|
+
| `upp/ingest` | Core (write) | Extract and ingest events from text |
|
|
85
|
+
| `upp/retrieve` | Core (read) | Intelligent retrieval of relevant events |
|
|
86
|
+
| `upp/events` | Core (read) | List all stored events |
|
|
87
|
+
| `upp/delete` | Core (write) | Delete events (GDPR compliance) |
|
|
88
|
+
| `upp/info` | Discovery | Server metadata |
|
|
89
|
+
| `upp/labels` | Discovery | Label definitions from an ontology |
|
|
90
|
+
| `upp/export` | Portability | Export events for migration |
|
|
91
|
+
| `upp/import` | Portability | Import events from another server |
|
|
92
|
+
|
|
93
|
+
## Requirements
|
|
94
|
+
|
|
95
|
+
- Python >= 3.11
|
|
96
|
+
- Pydantic >= 2.0.0
|
|
97
|
+
|
|
98
|
+
## Testing
|
|
99
|
+
|
|
100
|
+
```bash
|
|
101
|
+
pytest tests/ -v
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
## License
|
|
105
|
+
|
|
106
|
+
MIT — See [LICENSE](../../LICENSE) for details.
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["hatchling"]
|
|
3
|
+
build-backend = "hatchling.build"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "upp-python"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Python reference implementation of the Universal Personalization Protocol (UPP) data models"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "MIT"
|
|
11
|
+
requires-python = ">=3.11"
|
|
12
|
+
authors = [
|
|
13
|
+
{ name = "UPP Protocol Authors" },
|
|
14
|
+
]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 4 - Beta",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"License :: OSI Approved :: MIT License",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.11",
|
|
21
|
+
"Programming Language :: Python :: 3.12",
|
|
22
|
+
"Programming Language :: Python :: 3.13",
|
|
23
|
+
"Programming Language :: Python :: 3.14",
|
|
24
|
+
"Typing :: Typed",
|
|
25
|
+
]
|
|
26
|
+
keywords = ["personalization", "protocol", "user-profile", "pydantic", "json-rpc"]
|
|
27
|
+
dependencies = [
|
|
28
|
+
"pydantic>=2.0.0",
|
|
29
|
+
]
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
dev = [
|
|
33
|
+
"pytest>=8.0.0",
|
|
34
|
+
"pytest-asyncio>=0.23.0",
|
|
35
|
+
"pytest-cov",
|
|
36
|
+
"ruff",
|
|
37
|
+
"mypy",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[project.urls]
|
|
41
|
+
Homepage = "https://github.com/Contextually-AI/upp"
|
|
42
|
+
Documentation = "https://github.com/Contextually-AI/upp/tree/main/spec"
|
|
43
|
+
Repository = "https://github.com/Contextually-AI/upp"
|
|
44
|
+
Issues = "https://github.com/Contextually-AI/upp/issues"
|
|
45
|
+
Changelog = "https://github.com/Contextually-AI/upp/blob/main/CHANGELOG.md"
|
|
46
|
+
|
|
47
|
+
[tool.hatch.build.targets.wheel]
|
|
48
|
+
packages = ["src/upp"]
|
|
49
|
+
|
|
50
|
+
[tool.pytest.ini_options]
|
|
51
|
+
testpaths = ["tests"]
|
|
52
|
+
pythonpath = ["src"]
|
|
53
|
+
asyncio_mode = "auto"
|
|
54
|
+
|
|
55
|
+
[tool.ruff]
|
|
56
|
+
target-version = "py311"
|
|
57
|
+
line-length = 160
|
|
58
|
+
|
|
59
|
+
[tool.ruff.lint]
|
|
60
|
+
select = ["E", "F", "I", "N", "W", "UP", "B", "SIM"]
|
|
61
|
+
|
|
62
|
+
[tool.mypy]
|
|
63
|
+
python_version = "3.11"
|
|
64
|
+
strict = true
|
|
65
|
+
plugins = ["pydantic.mypy"]
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
"""UPP — Universal Personalization Protocol Python Reference Implementation.
|
|
2
|
+
|
|
3
|
+
This package provides the Python reference implementation of the Universal
|
|
4
|
+
Personalization Protocol (UPP) data models, backend interfaces, JSON-RPC
|
|
5
|
+
support, and a high-level client.
|
|
6
|
+
|
|
7
|
+
Quick Start::
|
|
8
|
+
|
|
9
|
+
from upp import UPPClient, OntologyUserV1
|
|
10
|
+
from upp import Event, StoredEvent, LabelDefinition
|
|
11
|
+
from upp import EventStatus, SourceType, SensitivityTier
|
|
12
|
+
|
|
13
|
+
Backend Protocols::
|
|
14
|
+
|
|
15
|
+
from upp import IngestBackend, RetrieverBackend, OntologyBackend
|
|
16
|
+
|
|
17
|
+
All public types are re-exported from sub-packages for convenience.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
from importlib.metadata import version as _pkg_version
|
|
21
|
+
|
|
22
|
+
__version__ = _pkg_version("upp-python")
|
|
23
|
+
|
|
24
|
+
# --- Backend Protocols ---
|
|
25
|
+
from upp.backends import (
|
|
26
|
+
IngestBackend,
|
|
27
|
+
OntologyBackend,
|
|
28
|
+
RetrieverBackend,
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
# --- Client ---
|
|
32
|
+
from upp.client import UPPClient
|
|
33
|
+
|
|
34
|
+
# --- Models ---
|
|
35
|
+
from upp.models import (
|
|
36
|
+
Cardinality,
|
|
37
|
+
ContextualizeResult,
|
|
38
|
+
Durability,
|
|
39
|
+
Event,
|
|
40
|
+
EventStatus,
|
|
41
|
+
LabelDefinition,
|
|
42
|
+
SensitivityTier,
|
|
43
|
+
SourceType,
|
|
44
|
+
StoredEvent,
|
|
45
|
+
TaskResult,
|
|
46
|
+
TaskStatus,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
# --- Ontologies ---
|
|
50
|
+
from upp.ontologies.user_v1 import OntologyUserV1
|
|
51
|
+
|
|
52
|
+
# --- RPC ---
|
|
53
|
+
from upp.rpc import (
|
|
54
|
+
ALL_METHODS,
|
|
55
|
+
EXTRACTION_FAILED,
|
|
56
|
+
INGEST_FAILED,
|
|
57
|
+
INTERNAL_ERROR,
|
|
58
|
+
INVALID_PARAMS,
|
|
59
|
+
INVALID_REQUEST,
|
|
60
|
+
METHOD_NOT_FOUND,
|
|
61
|
+
ONTOLOGY_NOT_FOUND,
|
|
62
|
+
PARSE_ERROR,
|
|
63
|
+
UPP_CONTEXTUALIZE,
|
|
64
|
+
UPP_DELETE,
|
|
65
|
+
UPP_EVENTS,
|
|
66
|
+
UPP_EXPORT,
|
|
67
|
+
UPP_GET_TASKS,
|
|
68
|
+
UPP_IMPORT,
|
|
69
|
+
UPP_INFO,
|
|
70
|
+
UPP_INGEST,
|
|
71
|
+
UPP_LABELS,
|
|
72
|
+
UPP_RETRIEVE,
|
|
73
|
+
USER_NOT_FOUND,
|
|
74
|
+
ContextualizeRequest,
|
|
75
|
+
ContextualizeResponse,
|
|
76
|
+
DeleteRequest,
|
|
77
|
+
DeleteResponse,
|
|
78
|
+
EventsRequest,
|
|
79
|
+
EventsResponse,
|
|
80
|
+
ExportRequest,
|
|
81
|
+
ExportResponse,
|
|
82
|
+
GetTasksRequest,
|
|
83
|
+
GetTasksResponse,
|
|
84
|
+
ImportRequest,
|
|
85
|
+
ImportResponse,
|
|
86
|
+
InfoRequest,
|
|
87
|
+
InfoResponse,
|
|
88
|
+
IngestRequest,
|
|
89
|
+
IngestResponse,
|
|
90
|
+
JsonRpcError,
|
|
91
|
+
JsonRpcNotification,
|
|
92
|
+
JsonRpcRequest,
|
|
93
|
+
JsonRpcResponse,
|
|
94
|
+
LabelsRequest,
|
|
95
|
+
LabelsResponse,
|
|
96
|
+
RetrieveRequest,
|
|
97
|
+
RetrieveResponse,
|
|
98
|
+
UppError,
|
|
99
|
+
decode_request,
|
|
100
|
+
decode_response,
|
|
101
|
+
encode_request,
|
|
102
|
+
encode_response,
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
__all__ = [
|
|
106
|
+
"__version__",
|
|
107
|
+
# Enumerations
|
|
108
|
+
"Cardinality",
|
|
109
|
+
"Durability",
|
|
110
|
+
"EventStatus",
|
|
111
|
+
"SensitivityTier",
|
|
112
|
+
"SourceType",
|
|
113
|
+
"TaskStatus",
|
|
114
|
+
# Core entities
|
|
115
|
+
"ContextualizeResult",
|
|
116
|
+
"Event",
|
|
117
|
+
"LabelDefinition",
|
|
118
|
+
"StoredEvent",
|
|
119
|
+
"TaskResult",
|
|
120
|
+
# Backend protocols
|
|
121
|
+
"OntologyBackend",
|
|
122
|
+
"RetrieverBackend",
|
|
123
|
+
"IngestBackend",
|
|
124
|
+
# RPC message types
|
|
125
|
+
"JsonRpcError",
|
|
126
|
+
"JsonRpcNotification",
|
|
127
|
+
"JsonRpcRequest",
|
|
128
|
+
"JsonRpcResponse",
|
|
129
|
+
# RPC operation models
|
|
130
|
+
"ContextualizeRequest",
|
|
131
|
+
"ContextualizeResponse",
|
|
132
|
+
"DeleteRequest",
|
|
133
|
+
"DeleteResponse",
|
|
134
|
+
"EventsRequest",
|
|
135
|
+
"EventsResponse",
|
|
136
|
+
"ExportRequest",
|
|
137
|
+
"ExportResponse",
|
|
138
|
+
"GetTasksRequest",
|
|
139
|
+
"GetTasksResponse",
|
|
140
|
+
"ImportRequest",
|
|
141
|
+
"ImportResponse",
|
|
142
|
+
"InfoRequest",
|
|
143
|
+
"InfoResponse",
|
|
144
|
+
"LabelsRequest",
|
|
145
|
+
"LabelsResponse",
|
|
146
|
+
"IngestRequest",
|
|
147
|
+
"IngestResponse",
|
|
148
|
+
"RetrieveRequest",
|
|
149
|
+
"RetrieveResponse",
|
|
150
|
+
# RPC method constants
|
|
151
|
+
"ALL_METHODS",
|
|
152
|
+
"UPP_CONTEXTUALIZE",
|
|
153
|
+
"UPP_DELETE",
|
|
154
|
+
"UPP_EVENTS",
|
|
155
|
+
"UPP_EXPORT",
|
|
156
|
+
"UPP_GET_TASKS",
|
|
157
|
+
"UPP_IMPORT",
|
|
158
|
+
"UPP_INFO",
|
|
159
|
+
"UPP_LABELS",
|
|
160
|
+
"UPP_INGEST",
|
|
161
|
+
"UPP_RETRIEVE",
|
|
162
|
+
# RPC error codes
|
|
163
|
+
"EXTRACTION_FAILED",
|
|
164
|
+
"INTERNAL_ERROR",
|
|
165
|
+
"INVALID_PARAMS",
|
|
166
|
+
"INVALID_REQUEST",
|
|
167
|
+
"METHOD_NOT_FOUND",
|
|
168
|
+
"ONTOLOGY_NOT_FOUND",
|
|
169
|
+
"INGEST_FAILED",
|
|
170
|
+
"PARSE_ERROR",
|
|
171
|
+
"USER_NOT_FOUND",
|
|
172
|
+
# Exception
|
|
173
|
+
"UppError",
|
|
174
|
+
# Codec
|
|
175
|
+
"decode_request",
|
|
176
|
+
"decode_response",
|
|
177
|
+
"encode_request",
|
|
178
|
+
"encode_response",
|
|
179
|
+
# Client
|
|
180
|
+
"UPPClient",
|
|
181
|
+
# Ontology
|
|
182
|
+
"OntologyUserV1",
|
|
183
|
+
]
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"""UPP Backend Interfaces.
|
|
2
|
+
|
|
3
|
+
This package defines the abstract backend protocols for the Universal
|
|
4
|
+
Personalization Protocol. Each backend is a :class:`typing.Protocol`
|
|
5
|
+
decorated with :func:`typing.runtime_checkable`.
|
|
6
|
+
|
|
7
|
+
Backend Protocols:
|
|
8
|
+
IngestBackend — Persists and retrieves stored events.
|
|
9
|
+
RetrieverBackend — Intelligent retrieval of relevant context.
|
|
10
|
+
OntologyBackend — Label definitions and server metadata.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
from upp.backends.ingest import IngestBackend
|
|
16
|
+
from upp.backends.ontology import OntologyBackend
|
|
17
|
+
from upp.backends.retriever import RetrieverBackend
|
|
18
|
+
|
|
19
|
+
__all__ = [
|
|
20
|
+
"OntologyBackend",
|
|
21
|
+
"RetrieverBackend",
|
|
22
|
+
"IngestBackend",
|
|
23
|
+
]
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"""UPP Ingest Backend Protocol.
|
|
2
|
+
|
|
3
|
+
Defines the :class:`IngestBackend` protocol for extracting and persisting
|
|
4
|
+
personal events from free text. The backend manages the full lifecycle of
|
|
5
|
+
events following an immutable event-sourcing pattern.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from __future__ import annotations
|
|
9
|
+
|
|
10
|
+
from typing import Protocol, runtime_checkable
|
|
11
|
+
|
|
12
|
+
from upp.models.events import Event, StoredEvent, TaskResult
|
|
13
|
+
|
|
14
|
+
__all__ = [
|
|
15
|
+
"IngestBackend",
|
|
16
|
+
]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
@runtime_checkable
|
|
20
|
+
class IngestBackend(Protocol):
|
|
21
|
+
"""Protocol for pluggable event ingestion.
|
|
22
|
+
|
|
23
|
+
An ingest backend receives free text, extracts relevant personal
|
|
24
|
+
facts, classifies them with ontology labels, handles supersession
|
|
25
|
+
for singular-cardinality labels, and persists the resulting events.
|
|
26
|
+
|
|
27
|
+
Implementations may use any extraction strategy (LLM, NLP, rules)
|
|
28
|
+
and any backing storage (in-memory, SQLite, PostgreSQL, Redis, etc.).
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
async def ingest(
|
|
32
|
+
self,
|
|
33
|
+
entity_key: str,
|
|
34
|
+
text: str,
|
|
35
|
+
) -> list[StoredEvent]:
|
|
36
|
+
"""Extract and persist events from free text.
|
|
37
|
+
|
|
38
|
+
The backend MUST:
|
|
39
|
+
|
|
40
|
+
1. Analyze the input text and extract relevant personal facts.
|
|
41
|
+
2. Classify each fact with one or more ontology labels.
|
|
42
|
+
3. Assign a UUID v4 ``id`` and a UTC ``created_at`` timestamp.
|
|
43
|
+
4. For singular-cardinality labels, mark existing valid events
|
|
44
|
+
with the same label as superseded.
|
|
45
|
+
|
|
46
|
+
Args:
|
|
47
|
+
entity_key: Unique identifier of the user.
|
|
48
|
+
text: Free text from which to extract events.
|
|
49
|
+
|
|
50
|
+
Returns:
|
|
51
|
+
A list of :class:`StoredEvent` objects with server-assigned metadata.
|
|
52
|
+
"""
|
|
53
|
+
...
|
|
54
|
+
|
|
55
|
+
async def delete_events(
|
|
56
|
+
self,
|
|
57
|
+
entity_key: str,
|
|
58
|
+
event_ids: list[str] | None = None,
|
|
59
|
+
) -> int:
|
|
60
|
+
"""Delete events for a user.
|
|
61
|
+
|
|
62
|
+
If ``event_ids`` is ``None``, deletes ALL events for the user
|
|
63
|
+
(right to erasure). Otherwise, deletes only the specified events.
|
|
64
|
+
|
|
65
|
+
Args:
|
|
66
|
+
entity_key: Unique identifier of the user.
|
|
67
|
+
event_ids: Optional list of specific event IDs to delete.
|
|
68
|
+
If ``None``, all events for the user are deleted.
|
|
69
|
+
|
|
70
|
+
Returns:
|
|
71
|
+
Number of events deleted.
|
|
72
|
+
"""
|
|
73
|
+
...
|
|
74
|
+
|
|
75
|
+
async def import_events(
|
|
76
|
+
self,
|
|
77
|
+
entity_key: str,
|
|
78
|
+
events: list[Event],
|
|
79
|
+
) -> list[StoredEvent]:
|
|
80
|
+
"""Import events for a user.
|
|
81
|
+
|
|
82
|
+
Persists events that were previously exported from another
|
|
83
|
+
UPP-compatible server.
|
|
84
|
+
|
|
85
|
+
Args:
|
|
86
|
+
entity_key: Unique identifier of the user.
|
|
87
|
+
events: Events to import.
|
|
88
|
+
|
|
89
|
+
Returns:
|
|
90
|
+
A list of :class:`StoredEvent` objects with server-assigned metadata.
|
|
91
|
+
"""
|
|
92
|
+
...
|
|
93
|
+
|
|
94
|
+
async def schedule_ingest(
|
|
95
|
+
self,
|
|
96
|
+
entity_key: str,
|
|
97
|
+
text: str,
|
|
98
|
+
) -> str:
|
|
99
|
+
"""Schedule an ingest operation to run in the background.
|
|
100
|
+
|
|
101
|
+
Args:
|
|
102
|
+
entity_key: Unique identifier of the user.
|
|
103
|
+
text: Free text from which to extract events.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
A task_id that can be used with get_tasks to check status.
|
|
107
|
+
"""
|
|
108
|
+
...
|
|
109
|
+
|
|
110
|
+
async def get_tasks(
|
|
111
|
+
self,
|
|
112
|
+
task_ids: list[str],
|
|
113
|
+
) -> list[TaskResult]:
|
|
114
|
+
"""Check the status of background tasks.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
task_ids: One or more task IDs to check.
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
A list of TaskResult objects with status and results.
|
|
121
|
+
"""
|
|
122
|
+
...
|