You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PTHMINT-119: SSE event stream support and EventManager (#59)
This change introduces Server-Sent Events (SSE) support and real-time event stream processing to the SDK. It implements the HTTPStreamingTransport protocol and a high-level EventManager to easily subscribe to order event streams via tokens or URLs. Additionally, the Order response model is updated with backward-compatible fields, comprehensive usage examples are added to the README, and robust unit and E2E tests are included to ensure streaming stability.
Copy file name to clipboardExpand all lines: README.md
+50-17Lines changed: 50 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -41,11 +41,14 @@ The SDK uses a small transport abstraction so you can choose (and swap) the unde
41
41
### How it works
42
42
43
43
- The SDK expects an object implementing the `HTTPTransport` / `HTTPResponse` protocols defined in `src/multisafepay/transport/http_transport.py`.
44
+
- Event stream subscriptions additionally require the transport to implement the `HTTPStreamingTransport` protocol (adds `open_stream(...)` returning an `HTTPStreamResponse` with `readline()`, `close()`, and `raise_for_status()`).
44
45
- If you do not provide a transport, the SDK defaults to `RequestsTransport`.
45
46
-`requests` is an optional extra:
46
47
- To use the default transport, install `multisafepay[requests]`.
47
48
- To avoid `requests`, inject your own transport (for example, `httpx` or `urllib3`).
48
49
50
+
The built-in `RequestsTransport` implements both `HTTPTransport` and `HTTPStreamingTransport`, so the same configured `requests.Session` is reused for regular requests and SSE streams. Custom transports that only implement `HTTPTransport` (`request(...)`) can still be used for regular API calls, but SSE subscriptions fail explicitly until they also implement `HTTPStreamingTransport`. The SDK does not fall back to another HTTP library for event streams.
51
+
49
52
### Custom transport example
50
53
51
54
```bash
@@ -87,10 +90,10 @@ from multisafepay.client import ScopedCredentialResolver
with event_manager.subscribe_order_events(order, timeout=45.0) as stream:
140
+
for event in stream:
141
+
print(event)
134
142
```
135
143
136
-
See terminal examples in `examples/terminal_manager/` and `examples/terminal_group_manager/`.
144
+
Use `subscribe_events(events_token=..., events_stream_url=...)` when the token and stream URL are already available separately.
145
+
146
+
SSE subscriptions use the same configured SDK transport as regular API calls. With the default transport this reuses the same `requests.Session`; with a custom transport, implement the `HTTPStreamingTransport` protocol (adds `open_stream(...)` on top of `HTTPTransport`) on that transport instead of opening a separate HTTP connection path.
137
147
138
148
### Development-only custom base URL override
139
149
@@ -180,6 +190,29 @@ In any non-dev profile (including default `release`), custom base URLs are block
180
190
181
191
Go to the folder `examples` to see how to use the SDK.
182
192
193
+
The event-stream example in `examples/event_manager/subscribe_events.py` requires:
0 commit comments