Skip to content

Repository files navigation

Prefect tasks for Twitter search and X API workflows

TwexAPI is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp.

Schedule 6 read-only Twitter search, profile, timeline, and trend tasks in Prefect 3. Store API keys in Prefect blocks.

Tasks

Workflow step Prefect task TwexAPI route
Search tweets search_tweets POST /twitter/advanced_search/page
Read tweet detail get_tweet POST /v2/tweet/detail
Search users search_users GET /twitter/search-user/{keyword}/{target_count}
Read a profile get_user GET /twitter/{screen_name}/about
Read a timeline page get_user_tweets POST /twitter/{screen_name}/timeline/page
Read trending tweets get_trends GET /twitter/global-trending/tweets

Use REST or an SDK for follower pagination or approved posting.

Install

pip install prefect-x-api-scraper

Store credentials

prefect block register -m prefect_x_api_scraper
from prefect_x_api_scraper import TwexApiCredentials

credentials = TwexApiCredentials(api_key="your_twexapi_key")
credentials.save("twexapi", overwrite=True)

Keep API keys in Prefect blocks. Never put them in flow source files.

Create a flow

from prefect import flow
from prefect_x_api_scraper import TwexApiCredentials, get_trends, search_tweets


@flow
async def twitter_signal_flow() -> dict:
    credentials = TwexApiCredentials.load("twexapi")

    tweets = await search_tweets(
        credentials,
        '"prefect" OR "workflow orchestration"',
        sort_by="Latest",
    )
    trends = await get_trends(credentials, country="United States", count=10)

    return {"tweets": tweets, "trends": trends}

Import tasks

from prefect_x_api_scraper import (
    get_trends,
    get_tweet,
    get_user,
    get_user_tweets,
    search_tweets,
    search_users,
)

Tasks return the raw TwexAPI JSON payload and support Prefect with_options:

from prefect_x_api_scraper import search_tweets

search_recent_tweets = search_tweets.with_options(
    name="Search recent tweets",
    retries=2,
    retry_delay_seconds=10,
)

The credentials block sends Authorization: Bearer.

Documentation

TwexAPI is an independent third-party service. Not affiliated with X Corp. "Twitter" and "X" are trademarks of X Corp.

About

Prefect tasks for scheduled Twitter search, profiles, timelines, and trends through TwexAPI. Not affiliated with X Corp.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages