Skip to main content
This guide builds on the Python SDK setup, which covers install and authentication.

Tweet search workflow to CSV, JSON Lines, or XLSX

Search with client.x.tweets.search, GET /x/tweets/search, and generated TweetSearchParams. Save CSV and JSON Lines for notebooks, workers, agents, queues, warehouses, and replay.
The method accepts the same query inputs as the REST endpoint.

q

Python argument q maps to REST q. It holds the required X (Twitter) search query with keywords, handles, hashtags, or operators.

limit

Python argument limit maps to REST limit. Use it as a 1 to 200 upper bound for a bounded pull. If page.has_next_page is true, keep the same q, filters, query_type, and limit. That applies when you continue with page.next_cursor.

cursor

Python argument cursor maps to REST cursor. Pass the opaque cursor from page.next_cursor to request the next page.

since_time

Python argument since_time maps to REST sinceTime. Use it as the ISO 8601 lower time bound.

until_time

Python argument until_time maps to REST untilTime. Use it as the ISO 8601 upper time bound.

query_type

Python argument query_type maps to REST queryType. Use Latest for chronological results or Top for engagement-ranked results.

Returned data & handoff

client.x.tweets.search returns a PaginatedTweets Pydantic model.

page.tweets

JSON field tweets. Contains SearchTweet records with id, text, optional author, and created_at. Records also carry like_count, reply_count, retweet_count, quote_count, bookmark_count, view_count, and is_note_tweet when available.

page.has_next_page

Python field page.has_next_page. JSON field has_next_page. Tells your script whether another page exists.

page.next_cursor

JSON field next_cursor. Store it only when page.has_next_page is true. For bounded pulls that return fewer tweets than limit, pass it back as cursor. Send the same query, filters, query_type, and limit with it.
Project page.tweets into CSV rows for analysts. Project them into JSON Lines rows in xquik-tweet-search.jsonl for queues and data lakes. If account teams need an XLSX workbook, load those rows into pandas or openpyxl. Store tweet_id, author_username, engagement counts, page_index, page_cursor, next_cursor, and has_next_page. With them, scripts resume from the last saved cursor without replaying raw SDK models. For explicit limit pulls, resume with the same query, filters, query_type, and limit. Only cursor changes.

Next steps