threadify-sdk 0.2.10__tar.gz → 0.4.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.
Files changed (35) hide show
  1. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/CHANGELOG.md +21 -0
  2. threadify_sdk-0.4.0/PKG-INFO +362 -0
  3. threadify_sdk-0.4.0/README.md +332 -0
  4. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/pyproject.toml +3 -1
  5. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/tests/test_connection.py +92 -44
  6. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/tests/test_notification.py +2 -2
  7. threadify_sdk-0.4.0/tests/test_otel_correlation.py +273 -0
  8. threadify_sdk-0.4.0/tests/test_parity.py +320 -0
  9. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/tests/test_thread.py +2 -2
  10. threadify_sdk-0.4.0/tests/test_thread_key.py +200 -0
  11. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/__init__.py +7 -1
  12. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/client.py +30 -12
  13. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/connection.py +217 -35
  14. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/data_retriever.py +15 -4
  15. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/models.py +69 -2
  16. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/otel_exporter.py +203 -46
  17. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/step.py +81 -12
  18. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/thread.py +21 -2
  19. threadify_sdk-0.4.0/threadify/waiting.py +205 -0
  20. threadify_sdk-0.4.0/threadify_sdk.egg-info/PKG-INFO +362 -0
  21. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify_sdk.egg-info/SOURCES.txt +4 -0
  22. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify_sdk.egg-info/requires.txt +4 -0
  23. threadify_sdk-0.2.10/PKG-INFO +0 -237
  24. threadify_sdk-0.2.10/README.md +0 -210
  25. threadify_sdk-0.2.10/threadify_sdk.egg-info/PKG-INFO +0 -237
  26. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/LICENSE +0 -0
  27. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/MANIFEST.in +0 -0
  28. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/setup.cfg +0 -0
  29. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/tests/test_client.py +0 -0
  30. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/tests/test_data_retriever.py +0 -0
  31. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/tests/test_models.py +0 -0
  32. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/tests/test_step.py +0 -0
  33. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify/notification.py +0 -0
  34. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify_sdk.egg-info/dependency_links.txt +0 -0
  35. {threadify_sdk-0.2.10 → threadify_sdk-0.4.0}/threadify_sdk.egg-info/top_level.txt +0 -0
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## [0.4.0] - 2026-09-23
4
+
5
+ ### Breaking changes
6
+
7
+ - Remove `Threadify.entity_profiles`, `EntityProfileManager`, `ManagementAPIError`
8
+ and `profile_slug`. Create profile types and named profiles with `threadify-cli`;
9
+ configure metrics in the Engine UI. Tracing and reference-based profile
10
+ generation are unchanged. Remove the unused PyYAML dependency.
11
+
12
+ ### Added
13
+
14
+ - Add `connection.thread(thread_key, label=, contract=, refs=, tags=)` to
15
+ atomically create or resume a thread using a durable application identifier,
16
+ with a new `ThreadOptions` type for the create/resume options.
17
+
18
+ ### Changed
19
+
20
+ - Use `threadify.thread_key` throughout the OpenTelemetry exporter and OTLP
21
+ ingestion for trace correlation, replacing the previous external-reference
22
+ correlation attribute.
23
+
3
24
  ## [0.2.0](https://github.com/creativeJoe007/ThreadifyEngine/compare/threadify-sdk-python-v0.1.0...threadify-sdk-python-v0.2.0) (2026-02-19)
4
25
 
5
26
 
@@ -0,0 +1,362 @@
1
+ Metadata-Version: 2.4
2
+ Name: threadify-sdk
3
+ Version: 0.4.0
4
+ Summary: Python SDK for Threadify — Service-delivery intelligence. Track every customer request from start to finish across every system, team, and partner. Visit: https://threadify.dev
5
+ Author-email: Threadify Team <team@threadify.dev>
6
+ License: MIT
7
+ Keywords: threadify,workflow,orchestration,websocket,graphql
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: License :: OSI Approved :: MIT License
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Programming Language :: Python :: 3.12
15
+ Classifier: Programming Language :: Python :: 3.13
16
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
17
+ Requires-Python: >=3.10
18
+ Description-Content-Type: text/markdown
19
+ License-File: LICENSE
20
+ Requires-Dist: websockets>=12.0
21
+ Requires-Dist: httpx>=0.27.0
22
+ Provides-Extra: otel
23
+ Requires-Dist: opentelemetry-sdk>=1.20; extra == "otel"
24
+ Provides-Extra: dev
25
+ Requires-Dist: pytest>=8.0; extra == "dev"
26
+ Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
27
+ Requires-Dist: ruff>=0.3; extra == "dev"
28
+ Requires-Dist: opentelemetry-sdk>=1.20; extra == "dev"
29
+ Dynamic: license-file
30
+
31
+ # Threadify Python SDK
32
+
33
+ Python SDK for [Threadify](https://threadify.dev) — Service-delivery intelligence that tracks every customer request from start to finish across every system, team, and partner.
34
+
35
+ - **Documentation:** [https://docs.threadify.dev](https://docs.threadify.dev)
36
+ - **Create an account:** [https://threadify.dev](https://threadify.dev)
37
+
38
+ ## Installation
39
+
40
+ ```bash
41
+ pip install threadify-sdk
42
+ ```
43
+
44
+ For local development:
45
+
46
+ ```bash
47
+ pip install -e ".[dev]"
48
+ ```
49
+
50
+ ## Quick Start
51
+
52
+ ```python
53
+ import asyncio
54
+ import logging
55
+ from threadify import Threadify
56
+
57
+
58
+ async def main():
59
+ try:
60
+ conn = await Threadify.connect(
61
+ "your-api-key",
62
+ service_name="orders-service",
63
+ )
64
+ except Exception as e:
65
+ logging.error(f"Failed to connect: {e}")
66
+ return
67
+
68
+ try:
69
+ thread = await conn.thread("order:ORD-123", {
70
+ "label": "Order ORD-123",
71
+ "contract": "order_processing",
72
+ "role": "customer",
73
+ "refs": {"order_id": "ORD-123"},
74
+ "tags": ["priority"],
75
+ })
76
+
77
+ await thread.add_refs({"crm_id": "CRM-456"})
78
+
79
+ # Easy chaining!
80
+ await (
81
+ thread.step("order_received")
82
+ .add_context({"orderId": "ORD-123"})
83
+ .success("Order accepted")
84
+ )
85
+ except Exception as e:
86
+ logging.error(f"Error in thread: {e}")
87
+ finally:
88
+ await conn.close()
89
+
90
+
91
+ if __name__ == "__main__":
92
+ asyncio.run(main())
93
+ ```
94
+
95
+ For self-hosting, pass `engine_url="https://threadify.example.com"`. WebSocket and GraphQL paths are derived from that base, including reverse-proxy prefixes. Explicit `ws_url` and `graphql_url` remain available for split deployments.
96
+
97
+ ## Entity profiles
98
+
99
+ Track a customer's activity across workflows by setting up a profile type with
100
+ the [Threadify CLI](https://docs.threadify.dev/cli):
101
+
102
+ ```yaml
103
+ # customers.yaml
104
+ name: Customers
105
+ type: [customer_id]
106
+ description: Customer workflows
107
+ ```
108
+
109
+ ```sh
110
+ threadify-cli config set api-url https://threadify.example.com
111
+ threadify-cli login
112
+ threadify-cli profile-types create --file customers.yaml
113
+ threadify-cli profiles create --type-id TYPE_ID --ref-value CUST-001 --name 'Jane Doe'
114
+ ```
115
+
116
+ Use the returned profile type ID for `TYPE_ID`. Include `customer_id` in your
117
+ thread references to connect each workflow to its customer. Threadify can also
118
+ create profiles as matching activity arrives. Open **Entity Profiles** in the
119
+ dashboard to explore that history and configure metrics.
120
+
121
+ ## Configuration
122
+
123
+ ### Connect options
124
+
125
+ Use keyword arguments with `Threadify.connect(...)`:
126
+
127
+ - `service_name`
128
+ - `engine_url` (one HTTP(S) deployment base, including any proxy prefix)
129
+ - `ws_url` (optional, defaults to production)
130
+ - `graphql_url`
131
+ - `debug`
132
+ - `max_in_flight`
133
+ - `connect_timeout`
134
+
135
+ Example:
136
+
137
+ ```python
138
+ from threadify import Threadify
139
+
140
+ conn = await Threadify.connect(
141
+ "your-api-key",
142
+ service_name="inventory-service",
143
+ debug=True,
144
+ )
145
+ ```
146
+
147
+ ### Join options
148
+
149
+ Use `Connection.join(...)` with keyword arguments:
150
+
151
+ - `token=...`
152
+ - `thread_id=...` and `role=...`
153
+
154
+ Example:
155
+
156
+ ```python
157
+ thread = await conn.join(token="jwt-token")
158
+ ```
159
+
160
+ Or:
161
+
162
+ ```python
163
+ thread = await conn.join(
164
+ thread_id="thread-123",
165
+ role="supplier",
166
+ )
167
+ ```
168
+
169
+ ### Create or resume a thread
170
+
171
+ `await connection.thread(thread_key, options=None)` atomically creates or resumes
172
+ an application-owned key within the tenant. Use a session, order, or process ID
173
+ that your application already knows; you do not need to persist Threadify's
174
+ internal `thread_id` between requests.
175
+
176
+ ```python
177
+ thread = await conn.thread("agent-session:123", {
178
+ "label": "Agent session",
179
+ "contract": "agent_contract",
180
+ "refs": {"customer_id": "123"},
181
+ "tags": ["priority"],
182
+ })
183
+
184
+ # A later request or another worker uses the same key without repeating options.
185
+ thread = await conn.thread("agent-session:123")
186
+ await thread.step("tool_call").add_context({"tool": "search"}).success()
187
+ ```
188
+
189
+ The optional dictionary accepts `label`, `contract`, `refs`, `tags`,
190
+ `service_name`, and `role`. `ThreadOptions` is exported for type annotations.
191
+ Labels, contracts, service names, and roles must be non-empty strings when
192
+ supplied; refs map non-empty string keys to string values, and tags are a list
193
+ of non-empty strings.
194
+
195
+ Options are creation defaults. Resuming loads the stored label, refs, tags,
196
+ contract name, and pinned contract version into the returned handle. Repeating
197
+ an existing contract is allowed; supplying a conflicting contract fails without
198
+ changing the thread. Use `await thread.add_refs({...})` to change references
199
+ explicitly. Metadata is available as `thread.thread_key`, `thread.label`,
200
+ `thread.contract_name`, `thread.contract_version`, `thread.refs`, and `thread.tags`.
201
+
202
+ Keys are trimmed, case-sensitive strings of at most 1024 UTF-8 bytes. Concurrent
203
+ calls with the same key resolve to one thread. A key-only call on an unknown key
204
+ creates a free-form thread, so initialize contracted sessions before collectors
205
+ or other workers report activity. Closed, completed, and cancelled threads reject
206
+ acquisition and further writes; use a new key for a new process. `join()` remains
207
+ available for internal IDs and invitation tokens.
208
+
209
+ ## Subscriptions
210
+
211
+ Preferred API:
212
+
213
+ - `subscribe(event, step_name, handler)`
214
+ - `unsubscribe(event, step_name)`
215
+
216
+ Supported event patterns:
217
+
218
+ - `step.success`
219
+ - `step.failed`
220
+ - `step.*`
221
+ - `rule.passed`
222
+ - `rule.violated`
223
+ - `rule.*`
224
+ - `*`
225
+
226
+ Example:
227
+
228
+ ```python
229
+ def handle_notification(notification):
230
+ if notification.is_violated:
231
+ print(notification.message)
232
+
233
+
234
+
235
+ conn.subscribe("rule.violated", "payment_step", handle_notification)
236
+ ```
237
+
238
+ ## Versioning & Releases
239
+
240
+ This SDK follows [Semantic Versioning](https://semver.org/) and [Conventional Commits](https://www.conventionalcommits.org/). Releases are automated via GitHub Actions.
241
+
242
+ - `fix: ...` -> Patch bump
243
+ - `feat: ...` -> Minor bump
244
+ - `feat!: ...` or `BREAKING CHANGE: ...` -> Major bump
245
+
246
+ ## OpenTelemetry Integration
247
+
248
+ The Python SDK includes the OpenTelemetry SpanExporter in the core package. Use
249
+ `BatchSpanProcessor`: synchronous `export()` waits for Engine acknowledgements
250
+ on its worker thread and returns failure if any span fails or the deadline expires.
251
+ It continues attempting unrelated spans in a failed batch and does not complete
252
+ sessions from that batch. Calling synchronous export on the connection event
253
+ loop is rejected to avoid a deadlock. Before closing that loop or the connection,
254
+ run `await asyncio.to_thread(provider.shutdown)` to drain queued spans. Use
255
+ `await asyncio.to_thread(provider.force_flush)` for an explicit flush.
256
+
257
+
258
+ ```python
259
+ from opentelemetry import trace
260
+ from opentelemetry.sdk.trace import TracerProvider
261
+ from opentelemetry.sdk.trace.export import BatchSpanProcessor
262
+ from threadify import Threadify
263
+
264
+ conn = await Threadify.connect("api-key", service_name="checkout-service")
265
+
266
+ # Create exporter
267
+ exporter = conn.create_span_exporter(options={"refs": ["order.id", "customer.id"]})
268
+
269
+ # Filter spans by name — exact match or prefix wildcard with *
270
+ exporter = conn.create_span_exporter(options={
271
+ "refs": ["order.id", "customer.id"],
272
+ "filters": ["invoke_llm", "adk.before*", "llm.*"],
273
+ })
274
+
275
+ provider = TracerProvider()
276
+ provider.add_span_processor(BatchSpanProcessor(exporter))
277
+ trace.set_tracer_provider(provider)
278
+
279
+ # Initialize before exporting spans when this session has a contract.
280
+ await conn.thread("agent-session:123", {"contract": "agent_contract"})
281
+ tracer = trace.get_tracer("agent")
282
+ with tracer.start_as_current_span("tool_call", attributes={
283
+ "threadify.thread_key": "agent-session:123",
284
+ }):
285
+ pass # Perform the instrumented operation.
286
+ ```
287
+
288
+ The exporter resolves `threadify.thread_key` using the same create-or-resume
289
+ operation as `connection.thread()`. Omit the contract on later spans; the stored
290
+ contract version is loaded automatically. Shared root spans keep the session open.
291
+ See [OTel correlation](OTEL_CORRELATION.md) for identity precedence and completion.
292
+
293
+ **Filter patterns:**
294
+
295
+ - `"invoke_llm"` — exact match
296
+ - `"adk.before*"` — prefix wildcard, drops any span starting with `adk.before`
297
+ - `"llm.*"` — prefix wildcard, drops any span starting with `llm.`
298
+
299
+ ## Testing
300
+
301
+ To run the SDK tests, execute:
302
+
303
+ ```bash
304
+ make test
305
+ ```
306
+
307
+ Alternatively, use `pytest`:
308
+
309
+ ```bash
310
+ python3 -m pytest
311
+ ```
312
+
313
+
314
+ ## Contract coordination (0.3)
315
+
316
+ ```python
317
+ from threadify import Threadify, WaitOptions, ThreadifyError
318
+
319
+ connection = await Threadify.connect(api_key, engine_url="https://threadify.example.com", service_name="payments")
320
+ threads = await connection.get_threads_by_ref({"order_id": "ORD-1001"}, status="active", limit=25)
321
+ thread = await connection.thread("order:ORD-1001")
322
+ grant = await thread.wait_for("charge", WaitOptions(timeout=15))
323
+ # Execute the permitted business operation here.
324
+ result = await thread.step("charge").add_context({"amount": 42}).success("charged", wait_for=True, timeout=15)
325
+ assert result.validation.decision == "passed"
326
+ # Resume validation of exactly this event if a previous caller stopped waiting.
327
+ await thread.wait_for_validation("charge", result.step_id)
328
+ ```
329
+
330
+ `wait_for()` now asks the Engine for a permission grant, carrying an invocation
331
+ ID into the subsequent step report and its default idempotency key. It sends one
332
+ request and waits for a final correlated response. The old notification-only
333
+ helper is named `wait_for_notification()`; it does not authorize execution.
334
+
335
+ Timeouts are in **seconds**, at most 300. Cancelling the Python task or reaching
336
+ its timeout cancels the remote wait. Before reporting a granted operation, use
337
+ `await grant.cancel()` if you decide not to execute it. Cancellation does not
338
+ restore consumed fresh prerequisites; another invocation may need a new
339
+ successful predecessor. A disconnect rejects
340
+ pending requests immediately. No write is automatically retried; timeout errors
341
+ retain `invocation_id`, `idempotency_key`, or `step_id` where available for recovery.
342
+ A submitted event can still be persisted after its caller times out.
343
+
344
+ With `wait_for=True`, duplicate, violated, unavailable, and mismatched validation
345
+ responses raise `ThreadifyError` with a stable `code`; an ordinary acknowledgement
346
+ is not a validation result. Normal non-waiting duplicate reports keep the existing
347
+ `StepResult.duplicate` behavior. Contract definitions and Gherkin are enforced by
348
+ the Engine; SDKs select the contract and role rather than parsing contracts.
349
+
350
+ Install `threadify-sdk[otel]` to use the OTEL exporter. It preserves the recorded
351
+ span start/end and span-event timestamps, including spans exported later.
352
+
353
+ ## Package CI and publishing
354
+
355
+ CI tests Python 3.10, 3.12, and 3.13, including OTEL and wait-protocol regressions.
356
+ The `pypi-publish.yml` workflow validates a matching `vX.Y.Z` tag, builds a wheel
357
+ and source archive, checks metadata and wheel imports, then publishes using
358
+ [PyPI Trusted Publishing](https://docs.pypi.org/trusted-publishers/using-a-publisher/).
359
+ Configure a trusted publisher for owner `ThreadifyDev`, repository `python-sdk`,
360
+ workflow `pypi-publish.yml`, environment `pypi` in the `threadify-sdk` PyPI project.
361
+ A manual workflow run builds artifacts without publishing. No release is created
362
+ by running local tests or pushing an ordinary branch.