prefect-xquik collection when a Prefect flow needs scheduled X (Twitter) reads: tweet search, tweet lookup, user search, user lookup, user timelines, or regional trends.
The current 0.1.5 release is read-focused. It ships one credentials block, an async Xquik client, and 6 Prefect tasks that return raw Xquik JSON dictionaries for downstream tasks, warehouses, dashboards, or alerts.
Prerequisites
- Xquik API key
- Python 3.10+
- Prefect 3
- Prefect work pool or local runner for scheduled deployments
Scheduled Workflows
Social Listening
Schedule
search_tweets to collect recent or top posts for a saved query, then pass raw JSON to reporting tasks.Profile Enrichment
Use
search_users and get_user to enrich customer, creator, or competitor records with current public profiles.Timeline Refresh
Run
get_user_tweets on a schedule to refresh public timelines with optional replies and parent-tweet context.Trend Alerts
Call
get_trends for worldwide or regional topics before downstream alert, dashboard, or warehouse steps.Install
PyPI publication is pending. Install the pinned GitHub release wheel:Credential Block
Store the API key in a Prefect block, not in flow source files. Setbase_url to the public Xquik REST base URL when creating the block.
Block Type
Xquik CredentialsAPI Key
Paste an Xquik API key from the dashboard.
Base URL
https://xquik.com/api/v1API Contract
Keep
2026-04-29 unless you intentionally pin a different public contract.Collection Shape
Credentials
XquikCredentials stores the API key, base URL, contract header, and timeout.Client
XquikClient uses httpx.AsyncClient, sends x-api-key, and raises XquikError for request or response failures.Tasks
6 async Prefect tasks cover read workflows for tweets, users, user timelines, and trends.
Returns
Tasks return raw Xquik JSON dictionaries. Shape rows in later Prefect tasks.
Retries
Use Prefect task options for retry policy and delay.
Scope
Version
0.1.5 is read-only. Use REST, SDKs, or MCP for writes, monitors, webhooks, and extraction jobs.Tasks
Search Tweets
search_tweets(credentials, query, limit=25, query_type="Latest") calls GET /x/tweets/search.Get Tweet
get_tweet(credentials, tweet_id) calls GET /x/tweets/{id}.Search Users
search_users(credentials, query, cursor=None) calls GET /x/users/search.Get User
get_user(credentials, user_id) calls GET /x/users/{id}. Usernames may include @.Get user timeline
get_user_tweets(credentials, user_id, include_replies=False) calls GET /x/users/{id}/tweets.Get Trends
get_trends(credentials, woeid=1, count=30) calls GET /x/trends.Copy-Ready Flow
Use this flow when a scheduled job should capture current posts and worldwide trends for a reporting task.Result Handoff
Tweet Pages
search_tweets and get_user_tweets return tweets, has_next_page, and next_cursor. Store the cursor with the job checkpoint.User Pages
search_users returns users, has_next_page, and next_cursor. get_user returns one public profile dictionary with fields such as id, username, name, followers, verified, and profilePicture.Trend Pages
get_trends returns trends, count, and woeid. Trend rows include name and can include description, query, and rank.Downstream Rows
Normalize raw dictionaries in a follow-up task before writing to Slack, Sheets, a warehouse, or a dashboard. Keep
tweet_rows with id, text, author.username, createdAt, and url; user_rows with id, username, name, followers, verified, and profilePicture; and trend_rows with name, rank, query, and description.REST and MCP Handoff
When a Prefect flow needs writes, monitors, webhooks, event replay, or extraction jobs, keep theprefect-xquik task scope focused on reads. Call REST, a generated SDK, or MCP from a follow-up task, then normalize REST camelCase fields to compact snake_case handoff rows before downstream retries.
Tweet or Reply Write
Call
POST /x/tweets through REST or an SDK. Pass public image or MP4 URLs in media; do not send media_ids. Store confirmed tweet_id and charged_credits, or store write_action_id and poll GET /x/write-actions/{id} before retrying a pending write.DM Media Handoff
Upload local media with
POST /x/media, pass exactly 1 returned mediaId as media_ids on POST /x/dm/{userId}, and store message_id, media_id, account, and user_id. Leave reply_to_message_id unset.Stored Event Replay
Call
GET /events with after when a flow needs stored monitor replay. Store event_id, monitor_id, monitor_type, occurred_at, has_more, and next_cursor, then pass next_cursor as the next after value.Extraction Job
Start or poll extraction jobs through REST, SDKs, or MCP. Store
extraction_id, tool_type, status, has_more, next_cursor, and the export path before loading CSV, JSON, or XLSX rows.Retry Pattern
Wrap the task with Prefect options when you want retries around transient API, network, or rate-limit failures.Retry-After for repeated 429 responses. Keep limit at or below 200 for bounded tweet search pulls. Pass next_cursor with the same query, query_type, and limit.
Failure Routing
XquikError exposes status_code and response_text when an HTTP response is available. Use them to decide whether the flow should fail fast, pause for account action, or retry later.
Inspect Status
Catch
XquikError and branch on status_code. Store response_text with the failed run for debugging.Fix Inputs
Treat
400 and 404 as non-retryable. Fix the query, ID, username, or cursor before rerunning.Pause Billing Stops
Treat
402 as an account action. Check subscription or credits before the next schedule.Back Off Reads
Treat
429, 500, 502, and 503 as retryable with Prefect retry settings and slower schedules.Pagination Handoff
Xquik returns cursor fields for paginated reads. Store the cursor in your task result or downstream state, then pass it back unchanged on the next run.query, query_type, and limit unchanged. Only cursor changes.
Production Notes
Credentials
Store API keys in Prefect blocks. Do not put API keys in deployment YAML, repository files, or logs.
Billing
X data reads use credits. Handle
402 no_subscription, 402 no_credits, and 402 insufficient_credits before retrying.Rate Limits
Read endpoints share a 60 per 1s user bucket. Retry only after the
Retry-After window.Raw JSON
Shape records in follow-up tasks before writing to Slack, Sheets, a warehouse, or a dashboard.
Read Scope
Use this collection for reads. Use REST, SDKs, or MCP when a flow needs writes, monitors, webhooks, or extraction jobs.
Version Pin
Pin the release wheel in production images until PyPI publication is available.
Next Steps
- Read Rate Limits for retry and backoff guidance.
- Read Error Handling for
401,402,429, and5xxrecovery. - Use Extraction Workflow when a job needs durable CSV, JSON, XLSX, Markdown, or PDF exports.
- Use MCP Tools when an AI agent should decide which Xquik endpoint to call.