Skip to main content
Streaming methods on 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 to client.stream.posts():

Using with asyncio

Keep-alive and idle timeout

The X API sends a blank-line heartbeat about every 20 seconds. Set idle_timeout (e.g., 60.0 seconds) to reconnect automatically if a connection stalls without closing, and on_keep_alive to observe heartbeats:

Managing rules

Add rules:
Delete rules:
List active rules:
See Build a Rule for rule syntax and operators, and the StreamClient reference for all streaming methods.