sockudo-python 2.0.0__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.
@@ -0,0 +1,364 @@
1
+ Metadata-Version: 2.4
2
+ Name: sockudo-python
3
+ Version: 2.0.0
4
+ Summary: Sockudo Python client SDK
5
+ Author: Sockudo
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/sockudo/sockudo/tree/master/client-sdks/sockudo-python
8
+ Project-URL: Repository, https://github.com/sockudo/sockudo
9
+ Project-URL: Issues, https://github.com/sockudo/sockudo/issues
10
+ Requires-Python: >=3.10
11
+ Description-Content-Type: text/markdown
12
+ License-File: LICENSE
13
+ Requires-Dist: httpx>=0.27.0
14
+ Requires-Dist: msgpack>=1.2.1
15
+ Requires-Dist: PyNaCl>=1.5.0
16
+ Requires-Dist: websockets>=12.0
17
+ Requires-Dist: vcdiff-decoder>=0.1.0
18
+ Provides-Extra: dev
19
+ Requires-Dist: build>=1.2.2; extra == "dev"
20
+ Requires-Dist: pytest>=8.0.0; extra == "dev"
21
+ Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
22
+ Requires-Dist: ruff>=0.9.0; extra == "dev"
23
+ Requires-Dist: twine>=6.0.0; extra == "dev"
24
+ Dynamic: license-file
25
+
26
+ # sockudo-python
27
+
28
+ Async Sockudo client SDK for Python.
29
+
30
+ `sockudo-python` is a Pusher-compatible realtime client for Python applications. It preserves the familiar subscribe/bind/channel model while adding Sockudo-native features such as filter-aware subscriptions, delta reconstruction, and encrypted channel handling.
31
+
32
+ ## Features
33
+
34
+ - Protocol V2 by default, with V1 compatibility
35
+ - Public, private, presence, and encrypted channels
36
+ - Proxy-backed presence history and presence snapshot helpers
37
+ - Tag filter and per-subscription event filter helpers
38
+ - Continuity-aware connection recovery (`stream_id` + `serial`)
39
+ - Message deduplication
40
+ - JSON, MessagePack, and Protobuf wire formats
41
+ - Fossil and Xdelta3/VCDIFF delta compression support
42
+ - User sign-in and watchlist event handling
43
+
44
+ ## Install
45
+
46
+ For apps, install the published package:
47
+
48
+ ```bash
49
+ pip install sockudo-python
50
+ ```
51
+
52
+ For local monorepo development, install from the local path:
53
+
54
+ ```bash
55
+ git clone https://github.com/sockudo/sockudo.git
56
+ pip install -e sockudo/client-sdks/sockudo-python
57
+ ```
58
+
59
+ Using `requirements.txt` for local development:
60
+
61
+ ```
62
+ -e ../sockudo/client-sdks/sockudo-python
63
+ ```
64
+
65
+ Using `pyproject.toml` for local development:
66
+
67
+ ```toml
68
+ [project]
69
+ dependencies = [
70
+ "sockudo-python @ file:///absolute/path/to/sockudo/client-sdks/sockudo-python",
71
+ ]
72
+ ```
73
+
74
+ From this workspace:
75
+
76
+ ```bash
77
+ pip install -e client-sdks/sockudo-python
78
+ ```
79
+
80
+ ## Quick Start
81
+
82
+ ```python
83
+ import asyncio
84
+
85
+ from sockudo_python import SockudoClient, SockudoOptions
86
+
87
+
88
+ async def main() -> None:
89
+ client = SockudoClient(
90
+ "app-key",
91
+ SockudoOptions(
92
+ cluster="local",
93
+ force_tls=False,
94
+ ws_host="127.0.0.1",
95
+ ws_port=6001,
96
+ ),
97
+ )
98
+
99
+ channel = client.subscribe("public-updates")
100
+ channel.bind("price-updated", lambda payload, meta: print(payload))
101
+
102
+ await client.connect()
103
+ await asyncio.sleep(30)
104
+ await client.disconnect()
105
+
106
+
107
+ asyncio.run(main())
108
+ ```
109
+
110
+ ## Advanced Usage
111
+
112
+ ### Private Channel Authorization
113
+
114
+ Use an endpoint URL (the default) or supply a fully custom async handler:
115
+
116
+ ```python
117
+ from sockudo_python import (
118
+ SockudoClient,
119
+ SockudoOptions,
120
+ ChannelAuthorizationOptions,
121
+ ChannelAuthorizationData,
122
+ ChannelAuthorizationRequest,
123
+ )
124
+
125
+
126
+ async def my_auth_handler(request: ChannelAuthorizationRequest) -> ChannelAuthorizationData:
127
+ # Call your own backend to produce a signed auth token.
128
+ return ChannelAuthorizationData(
129
+ auth="app-key:hmac-sha256-signature",
130
+ channel_data='{"user_id":"42"}',
131
+ )
132
+
133
+
134
+ client = SockudoClient(
135
+ "app-key",
136
+ SockudoOptions(
137
+ cluster="local",
138
+ ws_host="127.0.0.1",
139
+ ws_port=6001,
140
+ channel_authorization=ChannelAuthorizationOptions(
141
+ endpoint="https://api.example.com/sockudo/auth",
142
+ # Or override entirely:
143
+ custom_handler=my_auth_handler,
144
+ ),
145
+ ),
146
+ )
147
+
148
+ channel = client.subscribe("private-orders")
149
+ channel.bind("order-placed", lambda data, meta: print(data))
150
+
151
+ await client.connect()
152
+ ```
153
+
154
+ ### Presence Channels
155
+
156
+ ```python
157
+ channel = client.subscribe("presence-lobby")
158
+
159
+ channel.bind(
160
+ "pusher:subscription_succeeded",
161
+ lambda data, meta: print("members:", data),
162
+ )
163
+ channel.bind(
164
+ "pusher:member_added",
165
+ lambda data, meta: print("joined:", data),
166
+ )
167
+ channel.bind(
168
+ "pusher:member_removed",
169
+ lambda data, meta: print("left:", data),
170
+ )
171
+
172
+ await client.connect()
173
+ ```
174
+
175
+ ### Presence History
176
+
177
+ Client-side presence history is proxy-backed. The Python client does not sign the server REST API directly; configure a backend endpoint that accepts `{channel, params, action}` and proxies the request with server credentials.
178
+
179
+ ```python
180
+ from sockudo_python import PresenceHistoryOptions, PresenceHistoryParams, PresenceSnapshotParams
181
+
182
+ client = SockudoClient(
183
+ "app-key",
184
+ SockudoOptions(
185
+ cluster="local",
186
+ ws_host="127.0.0.1",
187
+ ws_port=6001,
188
+ presence_history=PresenceHistoryOptions(
189
+ endpoint="https://api.example.com/sockudo/presence-history",
190
+ ),
191
+ ),
192
+ )
193
+
194
+ channel = client.subscribe("presence-lobby")
195
+
196
+ page = await channel.history(
197
+ PresenceHistoryParams(limit=50, direction="newest_first")
198
+ )
199
+ if page.has_next():
200
+ next_page = await page.next()
201
+
202
+ snapshot = await channel.snapshot(PresenceSnapshotParams(at_serial=4))
203
+ ```
204
+
205
+ ### Filter-Aware Subscriptions
206
+
207
+ Server-side tag filtering is a V2 feature. Only messages whose tags match the filter expression are delivered to this subscription.
208
+
209
+ ```python
210
+ from sockudo_python import SubscriptionOptions, Filter
211
+
212
+ channel = client.subscribe(
213
+ "price:btc",
214
+ options=SubscriptionOptions(
215
+ filter=Filter.eq("market", "spot"),
216
+ ),
217
+ )
218
+
219
+ # Compound filters
220
+ channel = client.subscribe(
221
+ "price:btc",
222
+ options=SubscriptionOptions(
223
+ filter=Filter.and_(
224
+ Filter.eq("market", "spot"),
225
+ Filter.gt("spread", "0"),
226
+ ),
227
+ ),
228
+ )
229
+ ```
230
+
231
+ ### Delta Compression And Rewind
232
+
233
+ Request delta-compressed delivery to reduce bandwidth for channels that carry frequently-updated payloads:
234
+
235
+ ```python
236
+ from sockudo_python import SubscriptionOptions, ChannelDeltaSettings, DeltaAlgorithm
237
+
238
+ channel = client.subscribe(
239
+ "orderbook:btc-usd",
240
+ options=SubscriptionOptions(
241
+ delta=ChannelDeltaSettings(
242
+ enabled=True,
243
+ algorithm=DeltaAlgorithm.XDELTA3,
244
+ ),
245
+ ),
246
+ )
247
+ channel.bind("snapshot", lambda data, meta: print(data))
248
+
249
+ channel = client.subscribe(
250
+ "market:btc",
251
+ options=SubscriptionOptions(
252
+ rewind=SubscriptionRewind.seconds_back(30),
253
+ ),
254
+ )
255
+
256
+ client.bind("sockudo:resume_success", lambda data, _: print(data))
257
+ channel.bind("sockudo:rewind_complete", lambda data, _: print(data))
258
+ ```
259
+
260
+ ### Encrypted Channels
261
+
262
+ `private-encrypted-*` channels decrypt payloads automatically using the `shared_secret` returned by your auth endpoint or custom handler.
263
+
264
+ ```python
265
+ channel = client.subscribe("private-encrypted-documents")
266
+ channel.bind("doc-updated", lambda data, meta: print(data)) # data is already decrypted
267
+ ```
268
+
269
+ Your auth handler must populate `shared_secret` in `ChannelAuthorizationData`:
270
+
271
+ ```python
272
+ async def encrypted_auth(request: ChannelAuthorizationRequest) -> ChannelAuthorizationData:
273
+ return ChannelAuthorizationData(
274
+ auth="app-key:hmac-sha256-signature",
275
+ shared_secret="base64-encoded-32-byte-secret",
276
+ )
277
+ ```
278
+
279
+ ### User Sign-In
280
+
281
+ ```python
282
+ from sockudo_python import UserAuthenticationOptions
283
+
284
+
285
+ client = SockudoClient(
286
+ "app-key",
287
+ SockudoOptions(
288
+ cluster="local",
289
+ ws_host="127.0.0.1",
290
+ ws_port=6001,
291
+ user_authentication=UserAuthenticationOptions(
292
+ endpoint="https://api.example.com/sockudo/user-auth",
293
+ ),
294
+ ),
295
+ )
296
+
297
+ await client.connect()
298
+ await client.user.sign_in()
299
+ ```
300
+
301
+ ### Connection Lifecycle
302
+
303
+ Bind to connection state changes to react to connect, disconnect, and reconnect events:
304
+
305
+ ```python
306
+ def on_state_change(change) -> None:
307
+ print(f"connection: {change.previous} -> {change.current}")
308
+
309
+ client.connection.bind("state_change", on_state_change)
310
+ client.connection.bind("connected", lambda data, _: print("socket id:", data.get("socket_id")))
311
+ client.connection.bind("disconnected", lambda data, _: print("disconnected"))
312
+ client.connection.bind("error", lambda data, _: print("error:", data))
313
+
314
+ await client.connect()
315
+ ```
316
+
317
+ ### Protocol V2
318
+
319
+ V2 is the default. To explicitly request it or to downgrade to V1 for strict Pusher SDK compatibility:
320
+
321
+ ```python
322
+ # V2 (default) — enables continuity tokens, message_id, recovery, filters, delta
323
+ client = SockudoClient("app-key", SockudoOptions(cluster="local", protocol_version=2))
324
+
325
+ # V1 — plain Pusher protocol, compatible with official Pusher SDKs
326
+ client = SockudoClient("app-key", SockudoOptions(cluster="local", protocol_version=1))
327
+ ```
328
+
329
+ ## Requirements
330
+
331
+ - Python 3.11+
332
+ - `asyncio`-based; designed for use with `async`/`await`
333
+
334
+ ## Testing
335
+
336
+ Run the unit and integration test suite:
337
+
338
+ ```bash
339
+ pytest client-sdks/sockudo-python/tests
340
+ ```
341
+
342
+ Live integration tests against a local Sockudo server on port `6001`:
343
+
344
+ ```bash
345
+ SOCKUDO_LIVE_TESTS=1 pytest client-sdks/sockudo-python/tests
346
+ ```
347
+
348
+ The live suite covers:
349
+
350
+ - public subscribe + publish round-trip
351
+ - delta-enabled channel delivery
352
+ - encrypted channel decryption
353
+
354
+ ## CI/CD
355
+
356
+ GitHub Actions are managed from the monorepo root:
357
+
358
+ - CI: `.github/workflows/sdk-ci.yml`
359
+ - Publish: `.github/workflows/sdk-release.yml` with tag `client-python-vX.Y.Z`
360
+ - Setup: see `docs/sdk-publishing-2026.md` for PyPI trusted publishing.
361
+
362
+ ## Status
363
+
364
+ The package covers the core Sockudo feature set, including VCDIFF decoding, encrypted channel handling, and both supported delta algorithms, and is suitable for publishing as the official Python SDK.
@@ -0,0 +1,7 @@
1
+ sockudo_python/__init__.py,sha256=25P2ZPWGojIgZ4uRwSzzLP_-lnvZxEez8V-rfuUGOH8,1021
2
+ sockudo_python/client.py,sha256=ikkp1dcAaIuYOOnMu7NQReP8qPOZlnKhGG_ya-dGjdA,90377
3
+ sockudo_python-2.0.0.dist-info/licenses/LICENSE,sha256=Rfu09RfZYgdX4dvZwzmFVt2wfFYH87DKhvRy886D8Os,1064
4
+ sockudo_python-2.0.0.dist-info/METADATA,sha256=Y_DoObVloHeN1kN_XaNrE5YIAQnAXIgpPWw4hCu6MDo,9623
5
+ sockudo_python-2.0.0.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
6
+ sockudo_python-2.0.0.dist-info/top_level.txt,sha256=IpufJRKZsOCgU4MGDkM-aJ7hPw-Blzp4TDFKPCMHdbI,15
7
+ sockudo_python-2.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (82.0.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Sockudo
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 @@
1
+ sockudo_python