threadify-sdk 0.2.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.
- threadify_sdk-0.2.0/CHANGELOG.md +13 -0
- threadify_sdk-0.2.0/LICENSE +21 -0
- threadify_sdk-0.2.0/MANIFEST.in +3 -0
- threadify_sdk-0.2.0/PKG-INFO +181 -0
- threadify_sdk-0.2.0/README.md +154 -0
- threadify_sdk-0.2.0/pyproject.toml +68 -0
- threadify_sdk-0.2.0/setup.cfg +4 -0
- threadify_sdk-0.2.0/tests/test_client.py +69 -0
- threadify_sdk-0.2.0/tests/test_connection.py +277 -0
- threadify_sdk-0.2.0/tests/test_data_retriever.py +355 -0
- threadify_sdk-0.2.0/tests/test_models.py +161 -0
- threadify_sdk-0.2.0/tests/test_notification.py +179 -0
- threadify_sdk-0.2.0/tests/test_step.py +280 -0
- threadify_sdk-0.2.0/tests/test_thread.py +148 -0
- threadify_sdk-0.2.0/threadify/__init__.py +51 -0
- threadify_sdk-0.2.0/threadify/client.py +191 -0
- threadify_sdk-0.2.0/threadify/connection.py +505 -0
- threadify_sdk-0.2.0/threadify/data_retriever.py +476 -0
- threadify_sdk-0.2.0/threadify/models.py +285 -0
- threadify_sdk-0.2.0/threadify/notification.py +164 -0
- threadify_sdk-0.2.0/threadify/otel_exporter.py +318 -0
- threadify_sdk-0.2.0/threadify/step.py +312 -0
- threadify_sdk-0.2.0/threadify/thread.py +323 -0
- threadify_sdk-0.2.0/threadify_sdk.egg-info/PKG-INFO +181 -0
- threadify_sdk-0.2.0/threadify_sdk.egg-info/SOURCES.txt +26 -0
- threadify_sdk-0.2.0/threadify_sdk.egg-info/dependency_links.txt +1 -0
- threadify_sdk-0.2.0/threadify_sdk.egg-info/requires.txt +7 -0
- threadify_sdk-0.2.0/threadify_sdk.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [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
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* Add GitHub Actions CI workflows for Go and Python SDKs and remove unnecessary docstrings from Python test files. ([2a48d71](https://github.com/creativeJoe007/ThreadifyEngine/commit/2a48d71641ca2101b600746e234041aa09951ac8))
|
|
9
|
+
* Configure automated releases for Go and Python SDKs, update Go … ([ac7c46d](https://github.com/creativeJoe007/ThreadifyEngine/commit/ac7c46d658c2bc3b91ceff5d629851d89825d3b9))
|
|
10
|
+
* Configure automated releases for Go and Python SDKs, update Go module import path, and add versioning. ([6dbcf36](https://github.com/creativeJoe007/ThreadifyEngine/commit/6dbcf360eeeb0bf7edeab9db9a26c84bdff3da18))
|
|
11
|
+
* improve Go and Python SDK step method chaining by propagating errors internally rather than returning them directly. ([fa3199b](https://github.com/creativeJoe007/ThreadifyEngine/commit/fa3199b419c9415681126a3c17ded69cd9a69ba0))
|
|
12
|
+
* Introduce basic usage and notification examples for Python and Go SDKs, alongside new thread tests and CI/CD workflow updates. ([755b3e3](https://github.com/creativeJoe007/ThreadifyEngine/commit/755b3e35cd21b0e76457add21d17db90afff344d))
|
|
13
|
+
* python sdk impl ([c3a54a4](https://github.com/creativeJoe007/ThreadifyEngine/commit/c3a54a453631c8fb3e3bef360386578263606b75))
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Threadify
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,181 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: threadify-sdk
|
|
3
|
+
Version: 0.2.0
|
|
4
|
+
Summary: Python SDK for the Threadify Engine — workflow orchestration via WebSocket and GraphQL
|
|
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: dev
|
|
23
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
24
|
+
Requires-Dist: pytest-asyncio>=0.23; extra == "dev"
|
|
25
|
+
Requires-Dist: ruff>=0.3; extra == "dev"
|
|
26
|
+
Dynamic: license-file
|
|
27
|
+
|
|
28
|
+
# Threadify Python SDK
|
|
29
|
+
|
|
30
|
+
Python SDK for connecting to the Threadify Engine over WebSocket and querying archived data over GraphQL.
|
|
31
|
+
|
|
32
|
+
## Installation
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
pip install threadify-sdk
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
For local development:
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
pip install -e ".[dev]"
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
## Quick Start
|
|
45
|
+
|
|
46
|
+
```python
|
|
47
|
+
import asyncio
|
|
48
|
+
import logging
|
|
49
|
+
from threadify import Threadify
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
async def main():
|
|
53
|
+
try:
|
|
54
|
+
conn = await Threadify.connect(
|
|
55
|
+
"your-api-key",
|
|
56
|
+
service_name="orders-service",
|
|
57
|
+
ws_url="wss://eng.threadify.dev/threads",
|
|
58
|
+
)
|
|
59
|
+
except Exception as e:
|
|
60
|
+
logging.error(f"Failed to connect: {e}")
|
|
61
|
+
return
|
|
62
|
+
|
|
63
|
+
try:
|
|
64
|
+
thread = await conn.start(contract_name="order_flow")
|
|
65
|
+
|
|
66
|
+
# Easy chaining!
|
|
67
|
+
await (
|
|
68
|
+
thread.step("order_received")
|
|
69
|
+
.add_context({"orderId": "ORD-123"})
|
|
70
|
+
.success("Order accepted")
|
|
71
|
+
)
|
|
72
|
+
except Exception as e:
|
|
73
|
+
logging.error(f"Error in thread: {e}")
|
|
74
|
+
finally:
|
|
75
|
+
await conn.close()
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
if __name__ == "__main__":
|
|
79
|
+
asyncio.run(main())
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
`ws_url` is required. The SDK no longer uses a hardcoded default URL.
|
|
83
|
+
|
|
84
|
+
## Configuration
|
|
85
|
+
|
|
86
|
+
### Connect options
|
|
87
|
+
|
|
88
|
+
Use keyword arguments with `Threadify.connect(...)`:
|
|
89
|
+
|
|
90
|
+
- `service_name`
|
|
91
|
+
- `ws_url` (required)
|
|
92
|
+
- `graphql_url`
|
|
93
|
+
- `debug`
|
|
94
|
+
- `max_in_flight`
|
|
95
|
+
- `connect_timeout`
|
|
96
|
+
|
|
97
|
+
Example:
|
|
98
|
+
|
|
99
|
+
```python
|
|
100
|
+
from threadify import Threadify
|
|
101
|
+
|
|
102
|
+
conn = await Threadify.connect(
|
|
103
|
+
"your-api-key",
|
|
104
|
+
service_name="inventory-service",
|
|
105
|
+
ws_url="wss://eng.threadify.dev/threads",
|
|
106
|
+
debug=True,
|
|
107
|
+
)
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Join options
|
|
111
|
+
|
|
112
|
+
Use `Connection.join(...)` with keyword arguments:
|
|
113
|
+
|
|
114
|
+
- `token=...`
|
|
115
|
+
- `thread_id=...` and `role=...`
|
|
116
|
+
|
|
117
|
+
Example:
|
|
118
|
+
|
|
119
|
+
```python
|
|
120
|
+
thread = await conn.join(token="jwt-token")
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Or:
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
thread = await conn.join(
|
|
127
|
+
thread_id="thread-123",
|
|
128
|
+
role="supplier",
|
|
129
|
+
)
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
## Subscriptions
|
|
133
|
+
|
|
134
|
+
Preferred API:
|
|
135
|
+
|
|
136
|
+
- `subscribe(event, step_name, handler)`
|
|
137
|
+
- `unsubscribe(event, step_name)`
|
|
138
|
+
|
|
139
|
+
Supported event patterns:
|
|
140
|
+
|
|
141
|
+
- `step.success`
|
|
142
|
+
- `step.failed`
|
|
143
|
+
- `step.*`
|
|
144
|
+
- `rule.passed`
|
|
145
|
+
- `rule.violated`
|
|
146
|
+
- `rule.*`
|
|
147
|
+
- `*`
|
|
148
|
+
|
|
149
|
+
Example:
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
def handle_notification(notification):
|
|
153
|
+
if notification.is_violated:
|
|
154
|
+
print(notification.message)
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
conn.subscribe("rule.violated", "payment_step", handle_notification)
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
## Versioning & Releases
|
|
162
|
+
|
|
163
|
+
This SDK follows [Semantic Versioning](https://semver.org/) and [Conventional Commits](https://www.conventionalcommits.org/). Releases are automated via GitHub Actions.
|
|
164
|
+
|
|
165
|
+
- `fix: ...` -> Patch bump
|
|
166
|
+
- `feat: ...` -> Minor bump
|
|
167
|
+
- `feat!: ...` or `BREAKING CHANGE: ...` -> Major bump
|
|
168
|
+
|
|
169
|
+
## Testing
|
|
170
|
+
|
|
171
|
+
To run the SDK tests, execute:
|
|
172
|
+
|
|
173
|
+
```bash
|
|
174
|
+
make test
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
Alternatively, use `pytest`:
|
|
178
|
+
|
|
179
|
+
```bash
|
|
180
|
+
python3 -m pytest
|
|
181
|
+
```
|
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
# Threadify Python SDK
|
|
2
|
+
|
|
3
|
+
Python SDK for connecting to the Threadify Engine over WebSocket and querying archived data over GraphQL.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install threadify-sdk
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
For local development:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
pip install -e ".[dev]"
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
```python
|
|
20
|
+
import asyncio
|
|
21
|
+
import logging
|
|
22
|
+
from threadify import Threadify
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
async def main():
|
|
26
|
+
try:
|
|
27
|
+
conn = await Threadify.connect(
|
|
28
|
+
"your-api-key",
|
|
29
|
+
service_name="orders-service",
|
|
30
|
+
ws_url="wss://eng.threadify.dev/threads",
|
|
31
|
+
)
|
|
32
|
+
except Exception as e:
|
|
33
|
+
logging.error(f"Failed to connect: {e}")
|
|
34
|
+
return
|
|
35
|
+
|
|
36
|
+
try:
|
|
37
|
+
thread = await conn.start(contract_name="order_flow")
|
|
38
|
+
|
|
39
|
+
# Easy chaining!
|
|
40
|
+
await (
|
|
41
|
+
thread.step("order_received")
|
|
42
|
+
.add_context({"orderId": "ORD-123"})
|
|
43
|
+
.success("Order accepted")
|
|
44
|
+
)
|
|
45
|
+
except Exception as e:
|
|
46
|
+
logging.error(f"Error in thread: {e}")
|
|
47
|
+
finally:
|
|
48
|
+
await conn.close()
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
if __name__ == "__main__":
|
|
52
|
+
asyncio.run(main())
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
`ws_url` is required. The SDK no longer uses a hardcoded default URL.
|
|
56
|
+
|
|
57
|
+
## Configuration
|
|
58
|
+
|
|
59
|
+
### Connect options
|
|
60
|
+
|
|
61
|
+
Use keyword arguments with `Threadify.connect(...)`:
|
|
62
|
+
|
|
63
|
+
- `service_name`
|
|
64
|
+
- `ws_url` (required)
|
|
65
|
+
- `graphql_url`
|
|
66
|
+
- `debug`
|
|
67
|
+
- `max_in_flight`
|
|
68
|
+
- `connect_timeout`
|
|
69
|
+
|
|
70
|
+
Example:
|
|
71
|
+
|
|
72
|
+
```python
|
|
73
|
+
from threadify import Threadify
|
|
74
|
+
|
|
75
|
+
conn = await Threadify.connect(
|
|
76
|
+
"your-api-key",
|
|
77
|
+
service_name="inventory-service",
|
|
78
|
+
ws_url="wss://eng.threadify.dev/threads",
|
|
79
|
+
debug=True,
|
|
80
|
+
)
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
### Join options
|
|
84
|
+
|
|
85
|
+
Use `Connection.join(...)` with keyword arguments:
|
|
86
|
+
|
|
87
|
+
- `token=...`
|
|
88
|
+
- `thread_id=...` and `role=...`
|
|
89
|
+
|
|
90
|
+
Example:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
thread = await conn.join(token="jwt-token")
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Or:
|
|
97
|
+
|
|
98
|
+
```python
|
|
99
|
+
thread = await conn.join(
|
|
100
|
+
thread_id="thread-123",
|
|
101
|
+
role="supplier",
|
|
102
|
+
)
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
## Subscriptions
|
|
106
|
+
|
|
107
|
+
Preferred API:
|
|
108
|
+
|
|
109
|
+
- `subscribe(event, step_name, handler)`
|
|
110
|
+
- `unsubscribe(event, step_name)`
|
|
111
|
+
|
|
112
|
+
Supported event patterns:
|
|
113
|
+
|
|
114
|
+
- `step.success`
|
|
115
|
+
- `step.failed`
|
|
116
|
+
- `step.*`
|
|
117
|
+
- `rule.passed`
|
|
118
|
+
- `rule.violated`
|
|
119
|
+
- `rule.*`
|
|
120
|
+
- `*`
|
|
121
|
+
|
|
122
|
+
Example:
|
|
123
|
+
|
|
124
|
+
```python
|
|
125
|
+
def handle_notification(notification):
|
|
126
|
+
if notification.is_violated:
|
|
127
|
+
print(notification.message)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
conn.subscribe("rule.violated", "payment_step", handle_notification)
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
## Versioning & Releases
|
|
135
|
+
|
|
136
|
+
This SDK follows [Semantic Versioning](https://semver.org/) and [Conventional Commits](https://www.conventionalcommits.org/). Releases are automated via GitHub Actions.
|
|
137
|
+
|
|
138
|
+
- `fix: ...` -> Patch bump
|
|
139
|
+
- `feat: ...` -> Minor bump
|
|
140
|
+
- `feat!: ...` or `BREAKING CHANGE: ...` -> Major bump
|
|
141
|
+
|
|
142
|
+
## Testing
|
|
143
|
+
|
|
144
|
+
To run the SDK tests, execute:
|
|
145
|
+
|
|
146
|
+
```bash
|
|
147
|
+
make test
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
Alternatively, use `pytest`:
|
|
151
|
+
|
|
152
|
+
```bash
|
|
153
|
+
python3 -m pytest
|
|
154
|
+
```
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=64", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "threadify-sdk"
|
|
7
|
+
version = "0.2.0"
|
|
8
|
+
description = "Python SDK for the Threadify Engine — workflow orchestration via WebSocket and GraphQL"
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.10"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
keywords = ["threadify", "workflow", "orchestration", "websocket", "graphql"]
|
|
13
|
+
authors = [
|
|
14
|
+
{name = "Threadify Team", email = "team@threadify.dev"}
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
]
|
|
27
|
+
|
|
28
|
+
dependencies = [
|
|
29
|
+
"websockets>=12.0",
|
|
30
|
+
"httpx>=0.27.0",
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
[project.optional-dependencies]
|
|
34
|
+
dev = [
|
|
35
|
+
"pytest>=8.0",
|
|
36
|
+
"pytest-asyncio>=0.23",
|
|
37
|
+
"ruff>=0.3",
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
[tool.pytest.ini_options]
|
|
41
|
+
asyncio_mode = "auto"
|
|
42
|
+
testpaths = ["tests"]
|
|
43
|
+
|
|
44
|
+
[tool.ruff]
|
|
45
|
+
line-length = 100
|
|
46
|
+
target-version = "py310"
|
|
47
|
+
|
|
48
|
+
[tool.ruff.lint]
|
|
49
|
+
select = [
|
|
50
|
+
"E", # pycodestyle errors
|
|
51
|
+
"W", # pycodestyle warnings
|
|
52
|
+
"F", # pyflakes
|
|
53
|
+
"I", # isort
|
|
54
|
+
"B", # flake8-bugbear
|
|
55
|
+
"C4", # flake8-comprehensions
|
|
56
|
+
"UP", # pyupgrade
|
|
57
|
+
"ASYNC",# flake8-async
|
|
58
|
+
]
|
|
59
|
+
ignore = [
|
|
60
|
+
"E501", # line too long (handled by formatter)
|
|
61
|
+
"B008", # do not perform function calls in argument defaults
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
[tool.ruff.format]
|
|
65
|
+
quote-style = "double"
|
|
66
|
+
indent-style = "space"
|
|
67
|
+
skip-magic-trailing-comma = false
|
|
68
|
+
line-ending = "auto"
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from unittest.mock import AsyncMock
|
|
3
|
+
|
|
4
|
+
import pytest
|
|
5
|
+
|
|
6
|
+
from threadify.client import Threadify
|
|
7
|
+
from threadify.models import ConnectOptions
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class TestThreadifyConnect:
|
|
11
|
+
@pytest.mark.asyncio
|
|
12
|
+
async def test_requires_ws_url(self, monkeypatch):
|
|
13
|
+
ws_connect = AsyncMock(
|
|
14
|
+
side_effect=AssertionError("websockets.connect should not be called")
|
|
15
|
+
)
|
|
16
|
+
monkeypatch.setattr("threadify.client.websockets.connect", ws_connect)
|
|
17
|
+
|
|
18
|
+
with pytest.raises(ValueError, match="ws_url is required"):
|
|
19
|
+
await Threadify.connect("test-api-key", "test-service")
|
|
20
|
+
|
|
21
|
+
@pytest.mark.asyncio
|
|
22
|
+
async def test_connect_with_explicit_ws_url(self, monkeypatch):
|
|
23
|
+
ws = AsyncMock()
|
|
24
|
+
ws.send = AsyncMock()
|
|
25
|
+
ws.recv = AsyncMock(return_value=json.dumps({"action": "connect", "status": "success"}))
|
|
26
|
+
ws.close = AsyncMock()
|
|
27
|
+
|
|
28
|
+
ws_connect = AsyncMock(return_value=ws)
|
|
29
|
+
monkeypatch.setattr("threadify.client.websockets.connect", ws_connect)
|
|
30
|
+
|
|
31
|
+
conn = await Threadify.connect(
|
|
32
|
+
"test-api-key",
|
|
33
|
+
service_name="test-service",
|
|
34
|
+
ws_url="wss://example.com/threads",
|
|
35
|
+
)
|
|
36
|
+
|
|
37
|
+
ws_connect.assert_awaited_once_with("wss://example.com/threads")
|
|
38
|
+
sent = ws.send.call_args.args[0]
|
|
39
|
+
sent_msg = json.loads(sent)
|
|
40
|
+
assert sent_msg["action"] == "connect"
|
|
41
|
+
assert sent_msg["apiKey"] == "test-api-key"
|
|
42
|
+
assert sent_msg["serviceName"] == "test-service"
|
|
43
|
+
assert conn.is_connected is True
|
|
44
|
+
|
|
45
|
+
@pytest.mark.asyncio
|
|
46
|
+
async def test_connect_legacy_signature_still_supported(self, monkeypatch):
|
|
47
|
+
ws = AsyncMock()
|
|
48
|
+
ws.send = AsyncMock()
|
|
49
|
+
ws.recv = AsyncMock(return_value=json.dumps({"action": "connect", "status": "success"}))
|
|
50
|
+
ws.close = AsyncMock()
|
|
51
|
+
|
|
52
|
+
ws_connect = AsyncMock(return_value=ws)
|
|
53
|
+
monkeypatch.setattr("threadify.client.websockets.connect", ws_connect)
|
|
54
|
+
|
|
55
|
+
conn = await Threadify.connect(
|
|
56
|
+
"test-api-key",
|
|
57
|
+
"legacy-service",
|
|
58
|
+
ConnectOptions(ws_url="wss://example.com/threads"),
|
|
59
|
+
)
|
|
60
|
+
|
|
61
|
+
sent_msg = json.loads(ws.send.call_args.args[0])
|
|
62
|
+
assert sent_msg["serviceName"] == "legacy-service"
|
|
63
|
+
assert conn.is_connected is True
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
class TestThreadifyFactory:
|
|
67
|
+
def test_create_requires_ws_url(self):
|
|
68
|
+
with pytest.raises(ValueError, match="ws_url is required"):
|
|
69
|
+
Threadify.create("test-api-key")
|