client.stream hold open an HTTP connection and yield events as they arrive.
Filtered stream
Make sure you have added at least one rule before connecting toclient.stream.posts():
Using with asyncio
Keep-alive and idle timeout
The X API sends a blank-line heartbeat about every 20 seconds. Setidle_timeout (e.g., 60.0 seconds) to reconnect automatically if a connection stalls without closing, and on_keep_alive to observe heartbeats: