Add loan-advisor-agent
Browse files- loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/INSTALLER +1 -0
- loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/METADATA +479 -0
- loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/RECORD +12 -0
- loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/REQUESTED +0 -0
- loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/WHEEL +5 -0
- loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/licenses/AUTHORS +10 -0
- loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/licenses/LICENSE +27 -0
- loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/top_level.txt +1 -0
loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/INSTALLER
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
uv
|
loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/METADATA
ADDED
|
@@ -0,0 +1,479 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Metadata-Version: 2.4
|
| 2 |
+
Name: sse-starlette
|
| 3 |
+
Version: 3.3.4
|
| 4 |
+
Summary: SSE plugin for Starlette
|
| 5 |
+
Author-email: sysid <sysid@gmx.de>
|
| 6 |
+
License-Expression: BSD-3-Clause
|
| 7 |
+
Project-URL: Source, https://github.com/sysid/sse-starlette
|
| 8 |
+
Classifier: Development Status :: 5 - Production/Stable
|
| 9 |
+
Classifier: Environment :: Web Environment
|
| 10 |
+
Classifier: Intended Audience :: Developers
|
| 11 |
+
Classifier: Operating System :: OS Independent
|
| 12 |
+
Classifier: Programming Language :: Python :: 3
|
| 13 |
+
Classifier: Programming Language :: Python :: 3.10
|
| 14 |
+
Classifier: Programming Language :: Python :: 3.11
|
| 15 |
+
Classifier: Programming Language :: Python :: 3.12
|
| 16 |
+
Classifier: Programming Language :: Python :: 3.13
|
| 17 |
+
Classifier: Topic :: Internet :: WWW/HTTP
|
| 18 |
+
Requires-Python: >=3.10
|
| 19 |
+
Description-Content-Type: text/markdown
|
| 20 |
+
License-File: LICENSE
|
| 21 |
+
License-File: AUTHORS
|
| 22 |
+
Requires-Dist: starlette>=0.49.1
|
| 23 |
+
Requires-Dist: anyio>=4.7.0
|
| 24 |
+
Provides-Extra: examples
|
| 25 |
+
Requires-Dist: uvicorn>=0.34.0; extra == "examples"
|
| 26 |
+
Requires-Dist: fastapi>=0.115.12; extra == "examples"
|
| 27 |
+
Requires-Dist: sqlalchemy[asyncio]>=2.0.41; extra == "examples"
|
| 28 |
+
Requires-Dist: aiosqlite>=0.21.0; extra == "examples"
|
| 29 |
+
Provides-Extra: uvicorn
|
| 30 |
+
Requires-Dist: uvicorn>=0.34.0; extra == "uvicorn"
|
| 31 |
+
Provides-Extra: granian
|
| 32 |
+
Requires-Dist: granian>=2.3.1; extra == "granian"
|
| 33 |
+
Provides-Extra: daphne
|
| 34 |
+
Requires-Dist: daphne>=4.2.0; extra == "daphne"
|
| 35 |
+
Dynamic: license-file
|
| 36 |
+
|
| 37 |
+
# Server-Sent Events for [Starlette](https://github.com/encode/starlette) and [FastAPI](https://fastapi.tiangolo.com/)
|
| 38 |
+
|
| 39 |
+
[](https://pepy.tech/project/sse-starlette)
|
| 40 |
+
[![PyPI Version][pypi-image]][pypi-url]
|
| 41 |
+
[![Build Status][build-image]][build-url]
|
| 42 |
+
|
| 43 |
+
> Background: https://sysid.github.io/server-sent-events/
|
| 44 |
+
|
| 45 |
+
Production ready Server-Sent Events implementation for Starlette and FastAPI following the [W3C SSE specification](https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events).
|
| 46 |
+
|
| 47 |
+
## Installation
|
| 48 |
+
|
| 49 |
+
```bash
|
| 50 |
+
pip install sse-starlette
|
| 51 |
+
uv add sse-starlette
|
| 52 |
+
|
| 53 |
+
# To run the examples and demonstrations
|
| 54 |
+
uv add sse-starlette[examples]
|
| 55 |
+
|
| 56 |
+
# Recommended ASGI server
|
| 57 |
+
uv add sse-starlette[uvicorn,granian,daphne]
|
| 58 |
+
```
|
| 59 |
+
|
| 60 |
+
## Quick Start
|
| 61 |
+
|
| 62 |
+
```python
|
| 63 |
+
import asyncio
|
| 64 |
+
from starlette.applications import Starlette
|
| 65 |
+
from starlette.routing import Route
|
| 66 |
+
from sse_starlette import EventSourceResponse
|
| 67 |
+
|
| 68 |
+
async def generate_events():
|
| 69 |
+
for i in range(10):
|
| 70 |
+
yield {"data": f"Event {i}"}
|
| 71 |
+
await asyncio.sleep(1)
|
| 72 |
+
|
| 73 |
+
async def sse_endpoint(request):
|
| 74 |
+
return EventSourceResponse(generate_events())
|
| 75 |
+
|
| 76 |
+
app = Starlette(routes=[Route("/events", sse_endpoint)])
|
| 77 |
+
```
|
| 78 |
+
|
| 79 |
+
## Core Features
|
| 80 |
+
|
| 81 |
+
- **Standards Compliant**: Full SSE specification implementation
|
| 82 |
+
- **Framework Integration**: Native Starlette and FastAPI support
|
| 83 |
+
- **Async/Await**: Built on modern Python async patterns
|
| 84 |
+
- **Connection Management**: Automatic client disconnect detection
|
| 85 |
+
- **Graceful Shutdown**: Proper cleanup on server termination with cooperative shutdown support
|
| 86 |
+
- **Thread Safety**: Context-local event management for multi-threaded applications
|
| 87 |
+
- **Multi-Loop Support**: Works correctly with multiple asyncio event loops
|
| 88 |
+
|
| 89 |
+
For a detailed look at the internal task coordination, shutdown detection, and cancellation
|
| 90 |
+
flows, see [ARCHITECTURE.md](ARCHITECTURE.md).
|
| 91 |
+
|
| 92 |
+
## Key Components
|
| 93 |
+
|
| 94 |
+
### EventSourceResponse
|
| 95 |
+
|
| 96 |
+
The main response class that handles SSE streaming:
|
| 97 |
+
|
| 98 |
+
```python
|
| 99 |
+
from sse_starlette import EventSourceResponse
|
| 100 |
+
|
| 101 |
+
# Basic usage
|
| 102 |
+
async def stream_data():
|
| 103 |
+
for item in data:
|
| 104 |
+
yield {"data": item, "event": "update", "id": str(item.id)}
|
| 105 |
+
|
| 106 |
+
return EventSourceResponse(stream_data())
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### ServerSentEvent
|
| 110 |
+
|
| 111 |
+
For structured event creation:
|
| 112 |
+
|
| 113 |
+
```python
|
| 114 |
+
from sse_starlette import ServerSentEvent
|
| 115 |
+
|
| 116 |
+
event = ServerSentEvent(
|
| 117 |
+
data="Custom message",
|
| 118 |
+
event="notification",
|
| 119 |
+
id="msg-123",
|
| 120 |
+
retry=5000
|
| 121 |
+
)
|
| 122 |
+
```
|
| 123 |
+
|
| 124 |
+
### JSONServerSentEvent
|
| 125 |
+
|
| 126 |
+
For an easy way to send json data as SSE events:
|
| 127 |
+
|
| 128 |
+
```python
|
| 129 |
+
from sse_starlette import JSONServerSentEvent
|
| 130 |
+
|
| 131 |
+
event = JSONServerSentEvent(
|
| 132 |
+
data={"field":"value"}, # Anything serializable with json.dumps
|
| 133 |
+
)
|
| 134 |
+
```
|
| 135 |
+
|
| 136 |
+
## Advanced Usage
|
| 137 |
+
|
| 138 |
+
### Custom Ping Configuration
|
| 139 |
+
|
| 140 |
+
```python
|
| 141 |
+
from sse_starlette import ServerSentEvent
|
| 142 |
+
|
| 143 |
+
def custom_ping():
|
| 144 |
+
return ServerSentEvent(comment="Custom ping message")
|
| 145 |
+
|
| 146 |
+
return EventSourceResponse(
|
| 147 |
+
generate_events(),
|
| 148 |
+
ping=10, # Ping every 10 seconds
|
| 149 |
+
ping_message_factory=custom_ping
|
| 150 |
+
)
|
| 151 |
+
```
|
| 152 |
+
|
| 153 |
+
### Multi-Threaded Usage
|
| 154 |
+
|
| 155 |
+
sse-starlette now supports usage in multi-threaded applications and with multiple asyncio event loops:
|
| 156 |
+
|
| 157 |
+
```python
|
| 158 |
+
import threading
|
| 159 |
+
import asyncio
|
| 160 |
+
from sse_starlette import EventSourceResponse
|
| 161 |
+
|
| 162 |
+
def run_sse_in_thread():
|
| 163 |
+
"""SSE streaming works correctly in separate threads"""
|
| 164 |
+
loop = asyncio.new_event_loop()
|
| 165 |
+
asyncio.set_event_loop(loop)
|
| 166 |
+
|
| 167 |
+
async def thread_events():
|
| 168 |
+
for i in range(5):
|
| 169 |
+
yield {"data": f"Thread event {i}"}
|
| 170 |
+
await asyncio.sleep(1)
|
| 171 |
+
|
| 172 |
+
# This works without "Event bound to different loop" errors
|
| 173 |
+
response = EventSourceResponse(thread_events())
|
| 174 |
+
loop.close()
|
| 175 |
+
|
| 176 |
+
# Start SSE in multiple threads
|
| 177 |
+
for i in range(3):
|
| 178 |
+
thread = threading.Thread(target=run_sse_in_thread)
|
| 179 |
+
thread.start()
|
| 180 |
+
```
|
| 181 |
+
|
| 182 |
+
### Database Streaming (Thread-Safe)
|
| 183 |
+
|
| 184 |
+
```python
|
| 185 |
+
async def stream_database_results(request):
|
| 186 |
+
# CORRECT: Create session within generator context
|
| 187 |
+
async with AsyncSession() as session:
|
| 188 |
+
results = await session.execute(select(User))
|
| 189 |
+
for row in results:
|
| 190 |
+
if await request.is_disconnected():
|
| 191 |
+
break
|
| 192 |
+
yield {"data": row.name, "id": str(row.id)}
|
| 193 |
+
|
| 194 |
+
return EventSourceResponse(stream_database_results(request))
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
### Error Handling and Timeouts
|
| 198 |
+
|
| 199 |
+
```python
|
| 200 |
+
async def robust_stream(request):
|
| 201 |
+
try:
|
| 202 |
+
for i in range(100):
|
| 203 |
+
if await request.is_disconnected():
|
| 204 |
+
break
|
| 205 |
+
yield {"data": f"Item {i}"}
|
| 206 |
+
await asyncio.sleep(0.5)
|
| 207 |
+
except asyncio.CancelledError:
|
| 208 |
+
# Client disconnected - perform cleanup
|
| 209 |
+
raise
|
| 210 |
+
|
| 211 |
+
return EventSourceResponse(
|
| 212 |
+
robust_stream(request),
|
| 213 |
+
send_timeout=30, # Timeout hanging sends
|
| 214 |
+
headers={"Cache-Control": "no-cache"}
|
| 215 |
+
)
|
| 216 |
+
```
|
| 217 |
+
|
| 218 |
+
### Memory Channels Alternative
|
| 219 |
+
|
| 220 |
+
For complex data flows, use memory channels instead of generators:
|
| 221 |
+
|
| 222 |
+
```python
|
| 223 |
+
import anyio
|
| 224 |
+
from functools import partial
|
| 225 |
+
|
| 226 |
+
async def data_producer(send_channel):
|
| 227 |
+
async with send_channel:
|
| 228 |
+
for i in range(10):
|
| 229 |
+
await send_channel.send({"data": f"Item {i}"})
|
| 230 |
+
await anyio.sleep(1)
|
| 231 |
+
|
| 232 |
+
async def channel_endpoint(request):
|
| 233 |
+
send_channel, receive_channel = anyio.create_memory_object_stream(10)
|
| 234 |
+
|
| 235 |
+
return EventSourceResponse(
|
| 236 |
+
receive_channel,
|
| 237 |
+
data_sender_callable=partial(data_producer, send_channel)
|
| 238 |
+
)
|
| 239 |
+
```
|
| 240 |
+
|
| 241 |
+
### Cooperative Shutdown
|
| 242 |
+
|
| 243 |
+
By default, generators receive `CancelledError` immediately when the server shuts down. With
|
| 244 |
+
cooperative shutdown, generators can detect the shutdown signal, send farewell events to clients,
|
| 245 |
+
and exit gracefully within a configurable grace period.
|
| 246 |
+
|
| 247 |
+
```python
|
| 248 |
+
import anyio
|
| 249 |
+
from sse_starlette import EventSourceResponse
|
| 250 |
+
|
| 251 |
+
async def graceful_stream(request):
|
| 252 |
+
shutdown_event = anyio.Event()
|
| 253 |
+
|
| 254 |
+
async def generate():
|
| 255 |
+
try:
|
| 256 |
+
while not shutdown_event.is_set():
|
| 257 |
+
yield {"data": "tick"}
|
| 258 |
+
# Check for shutdown between iterations
|
| 259 |
+
with anyio.move_on_after(1.0):
|
| 260 |
+
await shutdown_event.wait()
|
| 261 |
+
# Shutdown detected — send farewell event
|
| 262 |
+
yield {"event": "shutdown", "data": "Server is shutting down"}
|
| 263 |
+
except anyio.get_cancelled_exc_class():
|
| 264 |
+
# Grace period expired — generator force-cancelled
|
| 265 |
+
raise
|
| 266 |
+
|
| 267 |
+
return EventSourceResponse(
|
| 268 |
+
generate(),
|
| 269 |
+
shutdown_event=shutdown_event, # Library sets this on shutdown
|
| 270 |
+
shutdown_grace_period=5.0, # Seconds to wait before force-cancel
|
| 271 |
+
)
|
| 272 |
+
```
|
| 273 |
+
|
| 274 |
+
**How it works:**
|
| 275 |
+
|
| 276 |
+
1. On server shutdown, the library sets your `shutdown_event`
|
| 277 |
+
2. Your generator sees the event and can yield final events
|
| 278 |
+
3. If the generator exits within `shutdown_grace_period`, shutdown is clean (no `CancelledError`)
|
| 279 |
+
4. If the generator doesn't exit in time, it is force-cancelled as before
|
| 280 |
+
|
| 281 |
+
**Important:** `shutdown_grace_period` should be less than your ASGI server's graceful shutdown
|
| 282 |
+
timeout (e.g. uvicorn's `--timeout-graceful-shutdown`), otherwise the process is killed before the
|
| 283 |
+
grace period expires.
|
| 284 |
+
|
| 285 |
+
Without `shutdown_event` (the default), behavior is identical to previous versions: immediate
|
| 286 |
+
cancellation on server shutdown.
|
| 287 |
+
|
| 288 |
+
## Configuration Options
|
| 289 |
+
|
| 290 |
+
### EventSourceResponse Parameters
|
| 291 |
+
|
| 292 |
+
| Parameter | Type | Default | Description |
|
| 293 |
+
|-----------|------|---------|-------------|
|
| 294 |
+
| `content` | `ContentStream` | Required | Async generator or iterable |
|
| 295 |
+
| `ping` | `int` | 15 | Ping interval in seconds (0 to disable) |
|
| 296 |
+
| `sep` | `str` | `"\r\n"` | Line separator (`\r\n`, `\r`, `\n`) |
|
| 297 |
+
| `send_timeout` | `float` | `None` | Send operation timeout in seconds |
|
| 298 |
+
| `headers` | `dict` | `None` | Additional HTTP headers |
|
| 299 |
+
| `ping_message_factory` | `Callable` | `None` | Custom ping message creator |
|
| 300 |
+
| `shutdown_event` | `anyio.Event` | `None` | Event set by library on server shutdown |
|
| 301 |
+
| `shutdown_grace_period` | `float` | `0` | Seconds to wait after setting `shutdown_event` before force-cancel |
|
| 302 |
+
|
| 303 |
+
### Client Disconnection
|
| 304 |
+
|
| 305 |
+
```python
|
| 306 |
+
async def monitored_stream(request):
|
| 307 |
+
events_sent = 0
|
| 308 |
+
try:
|
| 309 |
+
while events_sent < 100:
|
| 310 |
+
if await request.is_disconnected():
|
| 311 |
+
print(f"Client disconnected after {events_sent} events")
|
| 312 |
+
break
|
| 313 |
+
|
| 314 |
+
yield {"data": f"Event {events_sent}"}
|
| 315 |
+
events_sent += 1
|
| 316 |
+
await asyncio.sleep(1)
|
| 317 |
+
|
| 318 |
+
except asyncio.CancelledError:
|
| 319 |
+
print("Stream cancelled")
|
| 320 |
+
raise
|
| 321 |
+
```
|
| 322 |
+
|
| 323 |
+
## Testing
|
| 324 |
+
|
| 325 |
+
sse-starlette includes now comprehensive test isolation without manual setup. The library automatically handles event loop contexts, eliminating the need for manual state resets:
|
| 326 |
+
|
| 327 |
+
```python
|
| 328 |
+
# this is deprecated and not needed since version 3.0.0
|
| 329 |
+
import pytest
|
| 330 |
+
from sse_starlette import EventSourceResponse
|
| 331 |
+
|
| 332 |
+
@pytest.fixture
|
| 333 |
+
def reset_sse_app_status():
|
| 334 |
+
AppStatus.should_exit_event = None
|
| 335 |
+
yield
|
| 336 |
+
AppStatus.should_exit_event = None
|
| 337 |
+
```
|
| 338 |
+
|
| 339 |
+
## Production Considerations
|
| 340 |
+
|
| 341 |
+
### Performance Limits
|
| 342 |
+
|
| 343 |
+
- **Memory**: Each connection maintains a buffer. Monitor memory usage.
|
| 344 |
+
- **Connections**: Limited by system file descriptors and application design.
|
| 345 |
+
- **Network**: High-frequency events can saturate bandwidth.
|
| 346 |
+
|
| 347 |
+
### Error Recovery
|
| 348 |
+
|
| 349 |
+
Implement client-side reconnection logic:
|
| 350 |
+
|
| 351 |
+
```javascript
|
| 352 |
+
function createEventSource(url) {
|
| 353 |
+
const eventSource = new EventSource(url);
|
| 354 |
+
|
| 355 |
+
eventSource.onerror = function() {
|
| 356 |
+
setTimeout(() => {
|
| 357 |
+
createEventSource(url); // Reconnect after delay
|
| 358 |
+
}, 5000);
|
| 359 |
+
};
|
| 360 |
+
|
| 361 |
+
return eventSource;
|
| 362 |
+
}
|
| 363 |
+
```
|
| 364 |
+
|
| 365 |
+
## Learning Resources
|
| 366 |
+
|
| 367 |
+
### Examples Directory
|
| 368 |
+
|
| 369 |
+
The `examples/` directory contains production-ready patterns:
|
| 370 |
+
|
| 371 |
+
- **`01_basic_sse.py`**: Fundamental SSE concepts
|
| 372 |
+
- **`02_message_broadcasting.py`**: Multi-client message distribution
|
| 373 |
+
- **`03_database_streaming.py`**: Thread-safe database integration
|
| 374 |
+
- **`04_advanced_features.py`**: Custom protocols and error handling
|
| 375 |
+
|
| 376 |
+
### Demonstrations Directory
|
| 377 |
+
|
| 378 |
+
The `examples/demonstrations/` directory provides educational scenarios:
|
| 379 |
+
|
| 380 |
+
**Basic Patterns** (`basic_patterns/`):
|
| 381 |
+
- Client disconnect detection and cleanup
|
| 382 |
+
- Graceful server shutdown behavior
|
| 383 |
+
|
| 384 |
+
**Production Scenarios** (`production_scenarios/`):
|
| 385 |
+
- Load testing with concurrent clients
|
| 386 |
+
- Network interruption handling
|
| 387 |
+
|
| 388 |
+
**Advanced Patterns** (`advanced_patterns/`):
|
| 389 |
+
- Memory channels vs generators
|
| 390 |
+
- Error recovery and circuit breakers
|
| 391 |
+
- Custom protocol development
|
| 392 |
+
|
| 393 |
+
Run any demonstration:
|
| 394 |
+
```bash
|
| 395 |
+
python examples/demonstrations/basic_patterns/client_disconnect.py
|
| 396 |
+
python examples/demonstrations/production_scenarios/load_simulations.py
|
| 397 |
+
python examples/demonstrations/advanced_patterns/error_recovery.py
|
| 398 |
+
```
|
| 399 |
+
|
| 400 |
+
## Troubleshooting
|
| 401 |
+
|
| 402 |
+
### Common Issues
|
| 403 |
+
|
| 404 |
+
**Database session errors with async generators**
|
| 405 |
+
- Create database sessions inside generators, not as dependencies
|
| 406 |
+
|
| 407 |
+
**Hanging connections after client disconnect**
|
| 408 |
+
- Always check `await request.is_disconnected()` in loops
|
| 409 |
+
- Use `send_timeout` parameter to detect dead connections
|
| 410 |
+
|
| 411 |
+
If you are using Postman, please see: https://github.com/sysid/sse-starlette/issues/47#issuecomment-1445953826
|
| 412 |
+
|
| 413 |
+
### Performance Optimization
|
| 414 |
+
|
| 415 |
+
```python
|
| 416 |
+
# Connection limits
|
| 417 |
+
class ConnectionLimiter:
|
| 418 |
+
def __init__(self, max_connections=100):
|
| 419 |
+
self.semaphore = asyncio.Semaphore(max_connections)
|
| 420 |
+
|
| 421 |
+
async def limited_endpoint(self, request):
|
| 422 |
+
async with self.semaphore:
|
| 423 |
+
return EventSourceResponse(generate_events())
|
| 424 |
+
```
|
| 425 |
+
|
| 426 |
+
## Network-Level Gotchas
|
| 427 |
+
|
| 428 |
+
Network infrastructure components can buffer SSE streams, breaking real-time delivery. Here are the most common issues and solutions:
|
| 429 |
+
|
| 430 |
+
### Reverse Proxy Buffering (Nginx/Apache)
|
| 431 |
+
|
| 432 |
+
**Problem**: Nginx buffers responses by default, delaying SSE events until ~16KB accumulates.
|
| 433 |
+
|
| 434 |
+
**Solution**: Add the `X-Accel-Buffering: no` header.
|
| 435 |
+
|
| 436 |
+
**Nginx Configuration** (if you can't modify app headers):
|
| 437 |
+
```nginx
|
| 438 |
+
location /events {
|
| 439 |
+
proxy_pass http://localhost:8000;
|
| 440 |
+
proxy_http_version 1.1;
|
| 441 |
+
proxy_set_header Connection '';
|
| 442 |
+
proxy_buffering off; # Disable for this location
|
| 443 |
+
chunked_transfer_encoding off;
|
| 444 |
+
}
|
| 445 |
+
```
|
| 446 |
+
|
| 447 |
+
### CDN Issues
|
| 448 |
+
|
| 449 |
+
**Cloudflare**: Buffers ~100KB before flushing to clients, breaking real-time delivery.
|
| 450 |
+
**Akamai**: Edge servers buffer by default.
|
| 451 |
+
|
| 452 |
+
### Load Balancer Problems
|
| 453 |
+
|
| 454 |
+
**HAProxy**: Timeout settings must exceed heartbeat frequency.
|
| 455 |
+
```haproxy
|
| 456 |
+
# Ensure timeouts > ping interval
|
| 457 |
+
timeout client 60s # If ping every 45s
|
| 458 |
+
timeout server 60s
|
| 459 |
+
```
|
| 460 |
+
|
| 461 |
+
**F5 Load Balancers**: Buffer responses by default.
|
| 462 |
+
|
| 463 |
+
## Contributing
|
| 464 |
+
|
| 465 |
+
See examples and demonstrations for implementation patterns. Run tests with:
|
| 466 |
+
|
| 467 |
+
```bash
|
| 468 |
+
make test-unit # Unit tests only
|
| 469 |
+
make test # All tests including integration
|
| 470 |
+
```
|
| 471 |
+
|
| 472 |
+
<!-- Badges -->
|
| 473 |
+
[pypi-image]: https://badge.fury.io/py/sse-starlette.svg
|
| 474 |
+
[pypi-url]: https://pypi.org/project/sse-starlette/
|
| 475 |
+
[build-image]: https://github.com/sysid/sse-starlette/actions/workflows/build.yml/badge.svg
|
| 476 |
+
[build-url]: https://github.com/sysid/sse-starlette/actions/workflows/build.yml
|
| 477 |
+
[coverage-image]: https://codecov.io/gh/sysid/sse-starlette/branch/master/graph/badge.svg
|
| 478 |
+
<!--[coverage-url]: https://codecov.io/gh/sysid/sse-starlette-->
|
| 479 |
+
|
loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/RECORD
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
sse_starlette-3.3.4.dist-info/INSTALLER,sha256=5hhM4Q4mYTT9z6QB6PGpUAW81PGNFrYrdXMj4oM_6ak,2
|
| 2 |
+
sse_starlette-3.3.4.dist-info/METADATA,sha256=TZH4A0ULUMe28duFyHcwUcENbXs_2SBqxj5lbdBdXuQ,14481
|
| 3 |
+
sse_starlette-3.3.4.dist-info/RECORD,,
|
| 4 |
+
sse_starlette-3.3.4.dist-info/REQUESTED,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 5 |
+
sse_starlette-3.3.4.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
| 6 |
+
sse_starlette-3.3.4.dist-info/licenses/AUTHORS,sha256=wv9j0uzxKLvairGyAWgwpdoSQgL7uXFoaFu5lGrtPxo,395
|
| 7 |
+
sse_starlette-3.3.4.dist-info/licenses/LICENSE,sha256=gK9r_Mvr0sFNSquWaVyrmVDhdxkMyA9e-BnpmZaIPo4,1511
|
| 8 |
+
sse_starlette-3.3.4.dist-info/top_level.txt,sha256=-WvV5NMWkq_J766sZPusKqv8pESM-Dxugi96Lp9oer4,14
|
| 9 |
+
sse_starlette/__init__.py,sha256=RED0OJhDtvV1xP2QierTjR5S_pE1ncewXr48Oi0G28Q,218
|
| 10 |
+
sse_starlette/event.py,sha256=4hkckogryemb_OX6xQU51uhs7vTSKiUkJEXIhA0b6pw,2780
|
| 11 |
+
sse_starlette/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
| 12 |
+
sse_starlette/sse.py,sha256=hW68RnF-IhDTj8jWm1pP1lBMrVnMUGey1a-FWQV_XQ8,16432
|
loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/REQUESTED
ADDED
|
File without changes
|
loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/WHEEL
ADDED
|
@@ -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 |
+
|
loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/licenses/AUTHORS
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
sysid <sysid@gmx.de>
|
| 2 |
+
synodriver <diguohuangjiajinweijun@gmail.com>
|
| 3 |
+
Skyler Lewis <sblnog@gmail.com>
|
| 4 |
+
Margret `Pax` Williams <pax.margret@gmail.com>
|
| 5 |
+
nekonoshiri <gexira.halen.toms@gmail.com>
|
| 6 |
+
justindujardin <justin@dujardinconsulting.com>
|
| 7 |
+
Håvard Thom <34199185+havardthom@users.noreply.github.com>
|
| 8 |
+
Vaibhav Mule <vaibhavmule135@gmail.com>
|
| 9 |
+
issmirnov <smirnov_i@tass.ru>
|
| 10 |
+
Cyprien <courtot.c@gmail.com>
|
loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/licenses/LICENSE
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Copyright © 2020, [sysid](https://sysid.github.io/).
|
| 2 |
+
All rights reserved.
|
| 3 |
+
|
| 4 |
+
Redistribution and use in source and binary forms, with or without
|
| 5 |
+
modification, are permitted provided that the following conditions are met:
|
| 6 |
+
|
| 7 |
+
* Redistributions of source code must retain the above copyright notice, this
|
| 8 |
+
list of conditions and the following disclaimer.
|
| 9 |
+
|
| 10 |
+
* Redistributions in binary form must reproduce the above copyright notice,
|
| 11 |
+
this list of conditions and the following disclaimer in the documentation
|
| 12 |
+
and/or other materials provided with the distribution.
|
| 13 |
+
|
| 14 |
+
* Neither the name of the copyright holder nor the names of its
|
| 15 |
+
contributors may be used to endorse or promote products derived from
|
| 16 |
+
this software without specific prior written permission.
|
| 17 |
+
|
| 18 |
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
| 19 |
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
| 20 |
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
| 21 |
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
| 22 |
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
| 23 |
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
| 24 |
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
| 25 |
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
| 26 |
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
| 27 |
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
loan-advisor-agent/.venv/Lib/site-packages/sse_starlette-3.3.4.dist-info/top_level.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
sse_starlette
|