Skip to main content

ActivityClient

The ActivityClient provides methods for streaming X Activities and managing activity subscriptions.

stream

Stream of X Activities in real-time.
from xdk.streaming import StreamConfig

config = StreamConfig(
    max_retries=-1,  # Infinite retries
    initial_backoff=1.0,
    max_backoff=60.0
)

for event in client.activity.stream(
    backfill_minutes=5,
    stream_config=config
):
    print(f"Activity event: {event}")
backfill_minutes
int
The number of minutes of backfill requested.
start_time
str
YYYY-MM-DDTHH:mm:ssZ. The earliest UTC timestamp from which the Post labels will be provided.
end_time
str
YYYY-MM-DDTHH:mm:ssZ. The latest UTC timestamp from which the Post labels will be provided.
stream_config
StreamConfig
Optional StreamConfig for customizing retry behavior, timeouts, and callbacks.
StreamResponse
Generator
Generator that yields individual streaming data items. Automatically manages connection with exponential backoff retry logic.

create_subscription

Creates a subscription for an X activity event.
from xdk.activity.models import CreateSubscriptionRequest

response = client.activity.create_subscription(
    body=CreateSubscriptionRequest(
        event_type="post.created",
        webhook_url="https://example.com/webhook"
    )
)
body
CreateSubscriptionRequest
Request body containing subscription details.
CreateSubscriptionResponse
object
Response containing the created subscription details.

get_subscriptions

Get a list of active subscriptions for X Activity.
for page in client.activity.get_subscriptions(
    max_results=50
):
    for subscription in page.data:
        print(f"Subscription: {subscription.id}")
max_results
int
The maximum number of results to return per page.
pagination_token
str
This parameter is used to get the next ‘page’ of results.
GetSubscriptionsResponse
Iterator
Iterator that yields pages of subscriptions. Automatically handles pagination.

delete_subscription

Deletes a subscription for an X activity event.
response = client.activity.delete_subscription(
    subscription_id="1234567890"
)
subscription_id
str
required
The ID of the subscription to delete.
DeleteSubscriptionResponse
object
Response confirming the subscription was deleted.

Build docs developers (and LLMs) love