Back to use cases

    Use case / X DATA / Python 3 / Published

    Crypto Sentiment Analysis from X and Reddit with Python

    For a token watchlist, pull X posts from the last 24 hours and Reddit threads from Web Search, with mentions, top posts and a tone breakdown.

    Card for Crypto Sentiment Analysis from X and Reddit with Python

    Token Narrative Pulse is a small Python script for crypto sentiment analysis. For a token watchlist it pulls X posts from the last 24 hours and Reddit threads with GET /web and site:reddit.com, and writes a daily report: mentions per token, unique authors, top posts and a bullish, bearish or neutral breakdown with cited links.

    The problem

    Crypto narratives move fast on X and Reddit. Analysts want a daily read on which tokens people talk about, how many different people, and in what tone, without bot spam inflating the numbers.

    What the app does

    • Takes a watchlist of tokens and terms.
    • Pulls Top and Latest X posts per term from the last 24 hours.
    • Runs a single Desearch web search for Reddit threads with site:reddit.com in the query.
    • Runs AI Search on X only for a bullish, bearish and neutral breakdown with cited links.
    • Counts mentions and unique authors per token.
    • Flags duplicates and template bot posts.
    • Writes a report, a CSV of posts and a mentions chart.

    How it works

    1. X search. GET /twitter through the desearch-py SDK x_search, with sort=Top and sort=Latest per watchlist term and start_date set to yesterday (UTC).
    2. Reddit web search. One GET /web call through web_search, with site:reddit.com plus watchlist terms joined with OR as the query and start=0. Keep only links whose host is reddit.com or a subdomain. Web search results have no post date, so Reddit threads are not limited to the last 24 hours.
    3. AI Search on X. One POST /desearch/ai/search call through ai_search, with tools=["twitter"] only, date_filter="PAST_24_HOURS" and result_type="LINKS_WITH_FINAL_SUMMARY". A system message asks for a bullish, bearish and neutral breakdown with cited links.
    4. Clean. Drop X posts older than 24 hours, plus duplicates and template bots.
    5. Write the report.

    The code

    The X search, Reddit web search and AI Search steps, copied from collect() in pulse.py:

    PYTHON
    async def collect(count, outdir, raw_dir):
        now = dt.datetime.now(dt.timezone.utc)
        since = now - dt.timedelta(hours=24)
        start_date = since.strftime("%Y-%m-%d")  # GET /twitter takes a UTC day, not a timestamp
        costs, x_raw, ai_raw = [], {}, {}
        async with Desearch(api_key=os.environ["DESEARCH_API_KEY"]) as ds:
            print("X search (GET /twitter via desearch-py x_search):")
            for label, (query, _) in WATCHLIST.items():
                for sort in ("Top", "Latest"):
                    data = await timed(costs, f"x_search {query!r} sort={sort}",
                                       ds.x_search(query=query, sort=sort, count=count,
                                                   start_date=start_date, include_metadata=True))
                    x_raw[f"{label}|{sort}"] = dump(data) or []
            terms = " OR ".join(q for q, _ in WATCHLIST.values())
            print("Reddit (GET /web via desearch-py web_search):")
            data = await timed(costs, "web_search site:reddit.com",
                               ds.web_search(query=f"site:reddit.com {terms}", start=0, include_metadata=True))
            ai_raw["web"] = dump(data) or {}
            print("AI Search (POST /desearch/ai/search via desearch-py ai_search):")
            data = await timed(costs, "ai_search tools=['twitter']",
                               ds.ai_search(prompt=f"What are people saying in the last 24 hours about {terms}?",
                                            tools=["twitter"], date_filter="PAST_24_HOURS",
                                            result_type="LINKS_WITH_FINAL_SUMMARY",
                                            system_message=SYSTEM_MESSAGE, count=10,
                                            include_metadata=True))
            ai_raw["twitter"] = dump(data) or {}

    The folder has one script, pulse.py, a sample report in sample-output.md and the chart from that run.

    Endpoints

    • GET /twitter
    • GET /web
    • POST /desearch/ai/search

    Example output

    From a run on 2026-10-26 at 09:48 UTC with the default watchlist. All 10 calls succeeded. The X mention counts are deduplicated and inside the 24-hour window:

    TokenMentionsUnique authors
    TAO4841
    Bittensor4238
    Desearch (SN22)22
    Chutes (SN64)54

    94 posts returned, 78 unique, 69 inside the window. These are counts inside a sample, not total X volume.

    Web search returned 20 results, all on reddit.com.

    AI Search returned 10 X posts from the last 24 hours and a bullish, bearish and neutral summary citing 10 links, all among those posts.

    Run it yourself

    The public examples folder linked above includes the script and a README. Install its requirements, set DESEARCH_API_KEY from console.desearch.ai, and use the run command in that README.

    Useful flags: --count (posts per X query, default 20), --from-raw FILE (re-run with no API calls). Edit WATCHLIST in pulse.py to change tokens.

    What it costs

    One run with the default watchlist made 10 calls (8 X searches, 1 web search and 1 AI Search) and took about 45 seconds on 2026-10-26. See pricing.

    Ideas to extend it

    • Run it every morning and chart mentions over time.
    • Alert when unique authors for a token jump.
    • Add on-chain data next to the social view.

    Use with AI agents

    Point an MCP client at the hosted Desearch server. Replace the placeholder with a key from the console. Do not commit the key.

    JSON
    {
      "mcpServers": {
        "desearch": {
          "url": "https://mcp.desearch.ai/mcp",
          "headers": {
            "Authorization": "Bearer <key>"
          }
        }
      }
    }

    Prompt you can paste for this example:

    Use Desearch to pull public X posts from the last 24 hours for the tokens I name, and Reddit threads with GET /web and site:reddit.com. Summarize mention volume, the strongest posts, and the narrative you can support from those posts. Do not invent prices or posts.

    Build your own example.

    Give your agents access to web and social search. Get an API key to start building, or talk to us about your integration.

    Read docs