wse-server 1.2.0__tar.gz → 1.2.2__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 (47) hide show
  1. {wse_server-1.2.0 → wse_server-1.2.2}/PKG-INFO +35 -6
  2. {wse_server-1.2.0 → wse_server-1.2.2}/README.md +34 -5
  3. {wse_server-1.2.0 → wse_server-1.2.2}/pyproject.toml +1 -1
  4. {wse_server-1.2.0 → wse_server-1.2.2}/rust/Cargo.lock +1 -1
  5. {wse_server-1.2.0 → wse_server-1.2.2}/rust/Cargo.toml +1 -1
  6. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/__init__.py +1 -1
  7. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/connection.py +1 -1
  8. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/security.py +2 -4
  9. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/router.py +2 -3
  10. {wse_server-1.2.0 → wse_server-1.2.2}/LICENSE +0 -0
  11. {wse_server-1.2.0 → wse_server-1.2.2}/rust/.cargo/config.toml +0 -0
  12. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/jwt.rs +0 -0
  13. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/lib.rs +0 -0
  14. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/compression.rs +0 -0
  15. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/filters.rs +0 -0
  16. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/mod.rs +0 -0
  17. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/queue.rs +0 -0
  18. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/rate_limiter.rs +0 -0
  19. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/security.rs +0 -0
  20. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/sequencer.rs +0 -0
  21. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/server.rs +0 -0
  22. {wse_server-1.2.0 → wse_server-1.2.2}/rust/src/wse/transformer.rs +0 -0
  23. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/_accel.py +0 -0
  24. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/__init__.py +0 -0
  25. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/compression.py +0 -0
  26. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/handlers.py +0 -0
  27. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/manager.py +0 -0
  28. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/queue.py +0 -0
  29. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/sequencer.py +0 -0
  30. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/connection/transformer.py +0 -0
  31. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/core/__init__.py +0 -0
  32. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/core/filters.py +0 -0
  33. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/core/pubsub.py +0 -0
  34. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/core/types.py +0 -0
  35. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/dependencies.py +0 -0
  36. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/examples/__init__.py +0 -0
  37. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/examples/auth_handler.py +0 -0
  38. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/examples/event_mappings.py +0 -0
  39. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/examples/publisher.py +0 -0
  40. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/examples/snapshot_service.py +0 -0
  41. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/metrics/__init__.py +0 -0
  42. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/metrics/connection_metrics.py +0 -0
  43. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/py.typed +0 -0
  44. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/reliability/__init__.py +0 -0
  45. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/reliability/circuit_breaker.py +0 -0
  46. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/reliability/config.py +0 -0
  47. {wse_server-1.2.0 → wse_server-1.2.2}/wse_server/reliability/rate_limiter.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: wse-server
3
- Version: 1.2.0
3
+ Version: 1.2.2
4
4
  Classifier: Development Status :: 5 - Production/Stable
5
5
  Classifier: Framework :: FastAPI
6
6
  Classifier: Intended Audience :: Developers
@@ -72,7 +72,9 @@ The engine is Rust-accelerated via PyO3. Up to **2M msg/s** sustained throughput
72
72
 
73
73
  ## Quick Start
74
74
 
75
- ### Server (Python)
75
+ ### Server (Python) -- Router Mode
76
+
77
+ Embed WSE into your existing FastAPI app on the same port:
76
78
 
77
79
  ```python
78
80
  from fastapi import FastAPI
@@ -90,6 +92,31 @@ app.include_router(wse, prefix="/wse")
90
92
  await wse.publish("notifications", {"text": "Order shipped!", "order_id": 42})
91
93
  ```
92
94
 
95
+ ### Server (Python) -- Standalone Mode
96
+
97
+ Run the Rust WebSocket server on a dedicated port for maximum throughput:
98
+
99
+ ```python
100
+ from wse_server._wse_accel import RustWSEServer
101
+
102
+ server = RustWSEServer(
103
+ "0.0.0.0", 5006,
104
+ max_connections=10000,
105
+ jwt_secret=b"your-secret-key", # Rust JWT validation in handshake
106
+ jwt_issuer="your-app",
107
+ jwt_audience="your-api",
108
+ )
109
+ server.start()
110
+
111
+ # Drain inbound events in a background thread
112
+ while True:
113
+ events = server.drain_inbound(256, 50) # batch size, timeout ms
114
+ for event in events:
115
+ handle(event)
116
+ ```
117
+
118
+ Standalone mode gives you a dedicated Rust tokio runtime on its own port -- no FastAPI overhead, no GIL on the hot path. This is how WSE achieves 2M msg/s.
119
+
93
120
  ### Client (React)
94
121
 
95
122
  ```tsx
@@ -171,7 +198,7 @@ Compression, sequencing, filtering, rate limiting, and the WebSocket server itse
171
198
  | **Compression** | Flate2 zlib with configurable levels (1-9). Adaptive threshold -- only compress when payload exceeds size limit. Binary mode via msgpack (rmp-serde) for 30% smaller payloads. |
172
199
  | **Rate Limiter** | Atomic token-bucket rate limiter in Rust. Per-connection rate enforcement. 100K tokens capacity, 10K tokens/sec refill. |
173
200
  | **Message Deduplication** | AHashSet-backed dedup with bounded queue. Prevents duplicate delivery across reconnections and Redis fan-out. |
174
- | **Wire Envelope** | Protocol v2: `{t, id, ts, seq, p, v}`. Generic payload extraction with automatic type conversion (UUID, datetime, Enum, bytes to JSON-safe primitives). Latency tracking (`latency_ms` field). |
201
+ | **Wire Envelope** | Protocol v1: `{t, id, ts, seq, p, v}`. Generic payload extraction with automatic type conversion (UUID, datetime, Enum, bytes to JSON-safe primitives). Latency tracking (`latency_ms` field). |
175
202
  | **Snapshot Provider** | Protocol for initial state delivery. Implement `get_snapshot(user_id, topics)` and clients receive current state immediately on subscribe -- no waiting for the next publish cycle. |
176
203
  | **Circuit Breaker** | Three-state machine (CLOSED / OPEN / HALF_OPEN). Sliding-window failure tracking. Automatic recovery probes. Prevents cascade failures when downstream services are unhealthy. |
177
204
  | **Message Categories** | `S` (snapshot), `U` (update), `WSE` (system). Category prefixing for client-side routing and filtering. |
@@ -264,9 +291,11 @@ Client (React + TypeScript) Server (Python + Rust)
264
291
  ======================== ========================
265
292
 
266
293
  useWSE hook FastAPI Router (/wse)
267
- | |
268
- v v
269
- ConnectionPool Rust Engine (PyO3)
294
+ | -- OR --
295
+ v RustWSEServer (standalone :5006)
296
+ ConnectionPool |
297
+ | (multi-endpoint, v
298
+ | health scoring) Rust Engine (PyO3)
270
299
  | (multi-endpoint, | (drain mode,
271
300
  | health scoring) | write coalescing)
272
301
  v v
@@ -25,7 +25,9 @@ The engine is Rust-accelerated via PyO3. Up to **2M msg/s** sustained throughput
25
25
 
26
26
  ## Quick Start
27
27
 
28
- ### Server (Python)
28
+ ### Server (Python) -- Router Mode
29
+
30
+ Embed WSE into your existing FastAPI app on the same port:
29
31
 
30
32
  ```python
31
33
  from fastapi import FastAPI
@@ -43,6 +45,31 @@ app.include_router(wse, prefix="/wse")
43
45
  await wse.publish("notifications", {"text": "Order shipped!", "order_id": 42})
44
46
  ```
45
47
 
48
+ ### Server (Python) -- Standalone Mode
49
+
50
+ Run the Rust WebSocket server on a dedicated port for maximum throughput:
51
+
52
+ ```python
53
+ from wse_server._wse_accel import RustWSEServer
54
+
55
+ server = RustWSEServer(
56
+ "0.0.0.0", 5006,
57
+ max_connections=10000,
58
+ jwt_secret=b"your-secret-key", # Rust JWT validation in handshake
59
+ jwt_issuer="your-app",
60
+ jwt_audience="your-api",
61
+ )
62
+ server.start()
63
+
64
+ # Drain inbound events in a background thread
65
+ while True:
66
+ events = server.drain_inbound(256, 50) # batch size, timeout ms
67
+ for event in events:
68
+ handle(event)
69
+ ```
70
+
71
+ Standalone mode gives you a dedicated Rust tokio runtime on its own port -- no FastAPI overhead, no GIL on the hot path. This is how WSE achieves 2M msg/s.
72
+
46
73
  ### Client (React)
47
74
 
48
75
  ```tsx
@@ -124,7 +151,7 @@ Compression, sequencing, filtering, rate limiting, and the WebSocket server itse
124
151
  | **Compression** | Flate2 zlib with configurable levels (1-9). Adaptive threshold -- only compress when payload exceeds size limit. Binary mode via msgpack (rmp-serde) for 30% smaller payloads. |
125
152
  | **Rate Limiter** | Atomic token-bucket rate limiter in Rust. Per-connection rate enforcement. 100K tokens capacity, 10K tokens/sec refill. |
126
153
  | **Message Deduplication** | AHashSet-backed dedup with bounded queue. Prevents duplicate delivery across reconnections and Redis fan-out. |
127
- | **Wire Envelope** | Protocol v2: `{t, id, ts, seq, p, v}`. Generic payload extraction with automatic type conversion (UUID, datetime, Enum, bytes to JSON-safe primitives). Latency tracking (`latency_ms` field). |
154
+ | **Wire Envelope** | Protocol v1: `{t, id, ts, seq, p, v}`. Generic payload extraction with automatic type conversion (UUID, datetime, Enum, bytes to JSON-safe primitives). Latency tracking (`latency_ms` field). |
128
155
  | **Snapshot Provider** | Protocol for initial state delivery. Implement `get_snapshot(user_id, topics)` and clients receive current state immediately on subscribe -- no waiting for the next publish cycle. |
129
156
  | **Circuit Breaker** | Three-state machine (CLOSED / OPEN / HALF_OPEN). Sliding-window failure tracking. Automatic recovery probes. Prevents cascade failures when downstream services are unhealthy. |
130
157
  | **Message Categories** | `S` (snapshot), `U` (update), `WSE` (system). Category prefixing for client-side routing and filtering. |
@@ -217,9 +244,11 @@ Client (React + TypeScript) Server (Python + Rust)
217
244
  ======================== ========================
218
245
 
219
246
  useWSE hook FastAPI Router (/wse)
220
- | |
221
- v v
222
- ConnectionPool Rust Engine (PyO3)
247
+ | -- OR --
248
+ v RustWSEServer (standalone :5006)
249
+ ConnectionPool |
250
+ | (multi-endpoint, v
251
+ | health scoring) Rust Engine (PyO3)
223
252
  | (multi-endpoint, | (drain mode,
224
253
  | health scoring) | write coalescing)
225
254
  v v
@@ -4,7 +4,7 @@ build-backend = "maturin"
4
4
 
5
5
  [project]
6
6
  name = "wse-server"
7
- version = "1.2.0"
7
+ version = "1.2.2"
8
8
  description = "Real-time WebSocket engine for Python. Up to 2M msg/s sustained. End-to-end encrypted. Rust-accelerated via PyO3."
9
9
  readme = "README.md"
10
10
  license = { text = "MIT" }
@@ -1607,7 +1607,7 @@ dependencies = [
1607
1607
 
1608
1608
  [[package]]
1609
1609
  name = "wse-accel"
1610
- version = "1.2.0"
1610
+ version = "1.2.2"
1611
1611
  dependencies = [
1612
1612
  "aes-gcm",
1613
1613
  "ahash",
@@ -1,6 +1,6 @@
1
1
  [package]
2
2
  name = "wse-accel"
3
- version = "1.2.0"
3
+ version = "1.2.2"
4
4
  edition = "2024"
5
5
 
6
6
  [lib]
@@ -2,5 +2,5 @@
2
2
 
3
3
  from .router import SnapshotProvider, WSEConfig, create_wse_router
4
4
 
5
- __version__ = "1.2.0"
5
+ __version__ = "1.2.2"
6
6
  __all__ = ["create_wse_router", "WSEConfig", "SnapshotProvider"]
@@ -222,7 +222,7 @@ class WSEConnection:
222
222
  signed_message_types: frozenset = field(default_factory=lambda: DEFAULT_SIGNED_MESSAGE_TYPES)
223
223
 
224
224
  # Server info (for server_hello)
225
- server_version: str = "1.2.0"
225
+ server_version: str = "1.2.2"
226
226
  server_welcome_message: str = "Welcome to WSE"
227
227
 
228
228
  # Connection state
@@ -167,7 +167,7 @@ class SecurityManager:
167
167
 
168
168
  # Per-connection ECDH state
169
169
  self._conn_private_keys: dict[str, bytes] = {} # conn_id -> private key
170
- self._conn_public_keys: dict[str, bytes] = {} # conn_id -> our public key
170
+ self._conn_public_keys: dict[str, bytes] = {} # conn_id -> our public key
171
171
 
172
172
  # Fallback HMAC secret (auto-generated, used when no TokenProvider)
173
173
  self._hmac_secret: bytes = secrets.token_bytes(32)
@@ -257,9 +257,7 @@ class SecurityManager:
257
257
  # Encryption
258
258
  # -----------------------------------------------------------------
259
259
 
260
- async def encrypt_message(
261
- self, data: str | bytes | dict, conn_id: str = ""
262
- ) -> str | None:
260
+ async def encrypt_message(self, data: str | bytes | dict, conn_id: str = "") -> str | None:
263
261
  """Encrypt message using the active encryption provider.
264
262
 
265
263
  Returns base64-encoded ciphertext, or None if disabled/no key.
@@ -329,6 +329,7 @@ def create_wse_router(config: WSEConfig) -> APIRouter:
329
329
  encryption_public_key = None
330
330
  if encryption:
331
331
  import base64
332
+
332
333
  raw_pk = connection.security_manager.generate_keypair(conn_id)
333
334
  encryption_public_key = base64.b64encode(raw_pk).decode("ascii")
334
335
 
@@ -351,9 +352,7 @@ def create_wse_router(config: WSEConfig) -> APIRouter:
351
352
  "user_id": user_id,
352
353
  "endpoints": {
353
354
  "primary": (
354
- f"ws://{websocket.client.host}/ws/events"
355
- if websocket.client
356
- else None
355
+ f"ws://{websocket.client.host}/ws/events" if websocket.client else None
357
356
  ),
358
357
  "health_check_interval": 30_000,
359
358
  "heartbeat_interval": int(config.heartbeat_interval * 1000),
File without changes
File without changes
File without changes