trixdb 0.1.1__py3-none-any.whl

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.
trix/__init__.py ADDED
@@ -0,0 +1,301 @@
1
+ """
2
+ Trix Python SDK - Official Python client for Trix API.
3
+
4
+ Trix is a memory and knowledge management API that provides:
5
+ - Memory storage and retrieval
6
+ - Relationship management between memories
7
+ - Clustering and organization
8
+ - Graph traversal and analysis
9
+ - Semantic search
10
+ - Webhooks for event notifications
11
+ - Agent session management
12
+
13
+ Example:
14
+ >>> from trix import Trix
15
+ >>> client = Trix(api_key="your_api_key")
16
+ >>> memory = client.memories.create(content="Important information")
17
+ >>> print(memory.id)
18
+
19
+ Async Example:
20
+ >>> from trix import AsyncTrix
21
+ >>> async with AsyncTrix(api_key="your_api_key") as client:
22
+ ... memory = await client.memories.create(content="Important information")
23
+ ... print(memory.id)
24
+ """
25
+
26
+ # Version constants - must be defined before importing submodules to avoid circular imports
27
+ __version__ = "0.1.1"
28
+ __api_version__ = "v1"
29
+ MIN_API_VERSION = "v1"
30
+ MAX_API_VERSION = "v1"
31
+
32
+ # ruff: noqa: E402
33
+ from .client import (
34
+ AsyncTrix,
35
+ ErrorInterceptor,
36
+ PoolConfig,
37
+ RequestContext,
38
+ RequestInterceptor,
39
+ ResponseContext,
40
+ ResponseInterceptor,
41
+ Trix,
42
+ )
43
+ from .protocols import AsyncClientProtocol, ClientProtocol, SyncClientProtocol
44
+ from .utils.pagination import AsyncPaginator, SyncPaginator
45
+ from .utils.retry import RetryConfig
46
+ from .utils.security import (
47
+ validate_id,
48
+ validate_base_url,
49
+ validate_webhook_url,
50
+ redact_sensitive_data,
51
+ get_env_credential,
52
+ mask_credential,
53
+ )
54
+ from .utils.logging import (
55
+ LogConfig,
56
+ LogFormat,
57
+ LogLevel,
58
+ get_logger,
59
+ setup_logging,
60
+ request_context,
61
+ )
62
+ from .utils.metrics import (
63
+ InMemoryCollector,
64
+ MetricsCollector,
65
+ RequestMetrics,
66
+ get_metrics_collector,
67
+ set_metrics_collector,
68
+ timed_request,
69
+ )
70
+ from .utils.telemetry import (
71
+ TelemetryConfig,
72
+ SpanStatusCode,
73
+ SpanKind,
74
+ RequestSpan,
75
+ configure_telemetry,
76
+ get_telemetry_config,
77
+ is_telemetry_enabled,
78
+ create_request_span,
79
+ traced,
80
+ with_tracing,
81
+ with_tracing_async,
82
+ )
83
+ from .exceptions import (
84
+ APIError,
85
+ APIVersionMismatchError,
86
+ AuthenticationError,
87
+ ConnectionError,
88
+ NotFoundError,
89
+ PermissionError,
90
+ RateLimitError,
91
+ ServerError,
92
+ TimeoutError,
93
+ TrixError,
94
+ ValidationError,
95
+ )
96
+ from .types import (
97
+ AgentContext,
98
+ AgentSession,
99
+ BulkResult,
100
+ Cluster,
101
+ ClusterCreate,
102
+ ClusterList,
103
+ ClusterMembership,
104
+ ClusterUpdate,
105
+ ConsolidationResult,
106
+ ConsolidationStrategy,
107
+ Direction,
108
+ EmbedAllResponse,
109
+ EmbeddingResponse,
110
+ ExtractionType,
111
+ ExtractedHighlights,
112
+ FeedbackResponse,
113
+ FeedbackResult,
114
+ FeedbackSubmit,
115
+ GraphContext,
116
+ GraphNode,
117
+ GraphTraversal,
118
+ Highlight,
119
+ HighlightCreate,
120
+ HighlightList,
121
+ HighlightUpdate,
122
+ Job,
123
+ JobList,
124
+ JobStats,
125
+ JobStatus,
126
+ Memory,
127
+ MemoryConfig,
128
+ MemoryCreate,
129
+ MemoryList,
130
+ MemoryOptions,
131
+ MemoryType,
132
+ MemoryUpdate,
133
+ PaginatedResponse,
134
+ Pagination,
135
+ Relationship,
136
+ RelationshipCreate,
137
+ RelationshipList,
138
+ RelationshipType,
139
+ RelationshipUpdate,
140
+ SearchConfig,
141
+ SearchMode,
142
+ SearchResult,
143
+ SearchResults,
144
+ SessionMemory,
145
+ SessionMemoryList,
146
+ SessionList,
147
+ ShortestPath,
148
+ Space,
149
+ SpaceCreate,
150
+ SpaceList,
151
+ SpaceUpdate,
152
+ Webhook,
153
+ WebhookCreate,
154
+ WebhookDelivery,
155
+ WebhookDeliveryList,
156
+ WebhookEvent,
157
+ WebhookFilter,
158
+ WebhookList,
159
+ WebhookUpdate,
160
+ )
161
+
162
+ __all__ = [
163
+ # Clients
164
+ "Trix",
165
+ "AsyncTrix",
166
+ # Protocols
167
+ "SyncClientProtocol",
168
+ "AsyncClientProtocol",
169
+ "ClientProtocol",
170
+ # Utilities
171
+ "RetryConfig",
172
+ "PoolConfig",
173
+ "SyncPaginator",
174
+ "AsyncPaginator",
175
+ # Pagination types
176
+ "Pagination",
177
+ "PaginatedResponse",
178
+ "BulkResult",
179
+ # Interceptors
180
+ "RequestContext",
181
+ "ResponseContext",
182
+ "RequestInterceptor",
183
+ "ResponseInterceptor",
184
+ "ErrorInterceptor",
185
+ # Security utilities
186
+ "validate_id",
187
+ "validate_base_url",
188
+ "validate_webhook_url",
189
+ "redact_sensitive_data",
190
+ "get_env_credential",
191
+ "mask_credential",
192
+ # Logging utilities
193
+ "LogConfig",
194
+ "LogFormat",
195
+ "LogLevel",
196
+ "get_logger",
197
+ "setup_logging",
198
+ "request_context",
199
+ # Metrics utilities
200
+ "InMemoryCollector",
201
+ "MetricsCollector",
202
+ "RequestMetrics",
203
+ "get_metrics_collector",
204
+ "set_metrics_collector",
205
+ "timed_request",
206
+ # Telemetry utilities (OpenTelemetry integration)
207
+ "TelemetryConfig",
208
+ "SpanStatusCode",
209
+ "SpanKind",
210
+ "RequestSpan",
211
+ "configure_telemetry",
212
+ "get_telemetry_config",
213
+ "is_telemetry_enabled",
214
+ "create_request_span",
215
+ "traced",
216
+ "with_tracing",
217
+ "with_tracing_async",
218
+ # Exceptions
219
+ "TrixError",
220
+ "APIError",
221
+ "APIVersionMismatchError",
222
+ "AuthenticationError",
223
+ "PermissionError",
224
+ "NotFoundError",
225
+ "ValidationError",
226
+ "RateLimitError",
227
+ "ServerError",
228
+ "ConnectionError",
229
+ "TimeoutError",
230
+ # Types - Memory
231
+ "Memory",
232
+ "MemoryCreate",
233
+ "MemoryUpdate",
234
+ "MemoryList",
235
+ "MemoryConfig",
236
+ "MemoryOptions",
237
+ "MemoryType",
238
+ # Types - Relationship
239
+ "Relationship",
240
+ "RelationshipCreate",
241
+ "RelationshipUpdate",
242
+ "RelationshipList",
243
+ "RelationshipType",
244
+ # Types - Cluster
245
+ "Cluster",
246
+ "ClusterCreate",
247
+ "ClusterUpdate",
248
+ "ClusterList",
249
+ "ClusterMembership",
250
+ # Types - Space
251
+ "Space",
252
+ "SpaceCreate",
253
+ "SpaceUpdate",
254
+ "SpaceList",
255
+ # Types - Graph
256
+ "GraphNode",
257
+ "GraphTraversal",
258
+ "GraphContext",
259
+ "ShortestPath",
260
+ "Direction",
261
+ # Types - Search
262
+ "SearchResult",
263
+ "SearchResults",
264
+ "SearchConfig",
265
+ "SearchMode",
266
+ "EmbeddingResponse",
267
+ "EmbedAllResponse",
268
+ # Types - Webhook
269
+ "Webhook",
270
+ "WebhookCreate",
271
+ "WebhookUpdate",
272
+ "WebhookList",
273
+ "WebhookDelivery",
274
+ "WebhookDeliveryList",
275
+ "WebhookEvent",
276
+ "WebhookFilter",
277
+ # Types - Agent
278
+ "AgentSession",
279
+ "SessionMemory",
280
+ "SessionMemoryList",
281
+ "SessionList",
282
+ "ConsolidationResult",
283
+ "ConsolidationStrategy",
284
+ "AgentContext",
285
+ # Types - Feedback
286
+ "FeedbackSubmit",
287
+ "FeedbackResult",
288
+ "FeedbackResponse",
289
+ # Types - Highlights
290
+ "Highlight",
291
+ "HighlightCreate",
292
+ "HighlightUpdate",
293
+ "HighlightList",
294
+ "ExtractedHighlights",
295
+ "ExtractionType",
296
+ # Types - Jobs
297
+ "Job",
298
+ "JobList",
299
+ "JobStats",
300
+ "JobStatus",
301
+ ]
trix/auth.py ADDED
@@ -0,0 +1,73 @@
1
+ """Authentication handling for Trix SDK."""
2
+
3
+ from typing import Dict, Optional
4
+
5
+
6
+ class Auth:
7
+ """Handles authentication for Trix API requests."""
8
+
9
+ def __init__(self, api_key: Optional[str] = None, jwt_token: Optional[str] = None) -> None:
10
+ """
11
+ Initialize authentication.
12
+
13
+ Args:
14
+ api_key: API key for authentication
15
+ jwt_token: JWT token for authentication
16
+
17
+ Raises:
18
+ ValueError: If neither api_key nor jwt_token is provided
19
+ """
20
+ if not api_key and not jwt_token:
21
+ raise ValueError("Either api_key or jwt_token must be provided")
22
+
23
+ self._api_key = api_key
24
+ self._jwt_token = jwt_token
25
+
26
+ def get_headers(self) -> Dict[str, str]:
27
+ """
28
+ Get authentication headers.
29
+
30
+ Returns:
31
+ Dictionary of headers with Authorization bearer token
32
+ """
33
+ token = self._jwt_token or self._api_key
34
+ return {"Authorization": f"Bearer {token}"}
35
+
36
+ @property
37
+ def api_key(self) -> Optional[str]:
38
+ """Get the API key."""
39
+ return self._api_key
40
+
41
+ @property
42
+ def jwt_token(self) -> Optional[str]:
43
+ """Get the JWT token."""
44
+ return self._jwt_token
45
+
46
+ def update_jwt_token(self, jwt_token: str) -> None:
47
+ """
48
+ Update the JWT token.
49
+
50
+ Args:
51
+ jwt_token: New JWT token
52
+ """
53
+ self._jwt_token = jwt_token
54
+
55
+ def clear(self) -> None:
56
+ """
57
+ Clear all stored credentials.
58
+
59
+ This method should be called when closing the client to ensure
60
+ credentials are not retained in memory longer than necessary.
61
+ """
62
+ self._api_key = None
63
+ self._jwt_token = None
64
+
65
+ @property
66
+ def is_authenticated(self) -> bool:
67
+ """
68
+ Check if valid credentials are present.
69
+
70
+ Returns:
71
+ True if either API key or JWT token is set, False otherwise.
72
+ """
73
+ return bool(self._api_key or self._jwt_token)