twittrapi-haystack
Haystack integration for TwittrAPI, a pay-per-call REST API for public X (Twitter) data. No X developer account needed.
TwittrAPITweetSearch: a component that searches X and returns each tweet as a HaystackDocument, with the samedocumentsandlinksoutputs as the web-search components.TwittrAPIToolset: read-only X tools for Haystack Agents (search, profiles, timelines, followers, tweets with replies, quotes, retweets, Lists, Communities, trends).
Installation
pip install twittrapi-haystack
Create an API key at twittrapi.com and set it as TWITTRAPI_API_KEY.
New accounts get test credit.
TwittrAPITweetSearch
from haystack_integrations.components.websearch.twittrapi import TwittrAPITweetSearch
search = TwittrAPITweetSearch(top_k=20) # reads TWITTRAPI_API_KEY
result = search.run(query="haystack lang:en -filter:replies")
for doc in result["documents"]:
print(doc.meta["author_username"], doc.meta["likes"], doc.content)
print(result["next_cursor"]) # pass as cursor= for the next page
The query takes the operators of the X search box: from:user, to:user, "exact phrase",
lang:en, since:2026-01-01, until:2026-02-01, min_faves:100, filter:media,
-filter:replies and more.
Parameters
api_key: TwittrAPI key. Defaults to theTWITTRAPI_API_KEYenvironment variable.category:"Latest"(default, newest first),"Top","People"(accounts instead of tweets),"Photos"or"Videos". Can be changed perrun.top_k: results per page, 1 to 100 (default 20).
Outputs
documents: oneDocumentper tweet.contentis the full text;metaholdsid,url,created_at,lang,author_id,author_username,author_name,likes,retweets,replies,quotes,viewsandconversation_id.links: the tweet URLs, in the same order.next_cursor: cursor for the next page,Noneon the last page.
In a pipeline
from haystack import Pipeline
from haystack.components.builders import ChatPromptBuilder
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.components.websearch.twittrapi import TwittrAPITweetSearch
template = [
ChatMessage.from_user(
"Summarize what people say about {{ topic }} on X.\n"
"{% for doc in documents %}- @{{ doc.meta.author_username }}: {{ doc.content }}\n{% endfor %}"
)
]
pipe = Pipeline()
pipe.add_component("search", TwittrAPITweetSearch(top_k=30))
pipe.add_component("prompt", ChatPromptBuilder(template=template, required_variables=["topic", "documents"]))
pipe.add_component("llm", OpenAIChatGenerator(model="gpt-4o-mini"))
pipe.connect("search.documents", "prompt.documents")
pipe.connect("prompt.prompt", "llm.messages")
result = pipe.run({"search": {"query": "haystack lang:en"}, "prompt": {"topic": "Haystack"}})
print(result["llm"]["replies"][0].text)
TwittrAPIToolset
from haystack.components.agents import Agent
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack_integrations.tools.twittrapi import TwittrAPIToolset
agent = Agent(
chat_generator=OpenAIChatGenerator(model="gpt-4o-mini"),
tools=TwittrAPIToolset(), # reads TWITTRAPI_API_KEY
)
result = agent.run(messages=[ChatMessage.from_user("What has @deepset_ai posted this week?")])
print(result["messages"][-1].text)
| Tool | What it does |
|---|---|
search_tweets |
Search X with search operators; People returns accounts |
get_user_by_username / get_user_by_id |
A profile with counts and the numeric user ID |
get_user_tweets |
A user's recent tweets |
get_followers / get_following |
Followers and followed accounts |
get_tweet |
A tweet with its reply thread |
get_tweet_retweets / get_tweet_quotes |
Who retweeted a tweet, and the tweets quoting it |
get_list_tweets |
Latest tweets from an X List |
get_community_tweets |
Tweets in an X Community |
get_trends / get_trend_locations |
Trending topics by location (WOEID) |
Pick a subset with TwittrAPIToolset(tool_names=["search_tweets", "get_user_tweets"]). Results are
TwittrAPI's compact simple format (flat JSON), cut at
max_chars (default 20,000). Paginated tools print next_cursor first so the agent can page on. API
errors, such as an empty balance, are returned to the agent as the tool result.
Pricing
Every call is billed to your prepaid TwittrAPI balance. Prices are on twittrapi.com/pricing.
Links
License
MIT
Metadata
Release files for twittrapi-haystack 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| twittrapi_haystack-0.1.0.tar.gz | 11.5 kB | With provenance | Details for twittrapi_haystack-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| twittrapi_haystack-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for twittrapi_haystack-0.1.0-py3-none-any.whl |
Total release size: 23.5 kB
Release files / twittrapi_haystack-0.1.0.tar.gz
| Download URL | twittrapi_haystack-0.1.0.tar.gz |
|---|---|
| Size | 11.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
68e7b1e82403f8115d4c6355c3fa7cf77574eea0f4b9bf6d94c4d97926407d5b
|
|
BLAKE2b-256 checksum How to use checksums |
95ebb816220ab92d8f7fadca58bfbebee077eb3d04c10b5bb30fa0677332d864
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logRelease files / twittrapi_haystack-0.1.0-py3-none-any.whl
| Download URL | twittrapi_haystack-0.1.0-py3-none-any.whl |
|---|---|
| Size | 12.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
1c9849a96e6b000cb5a120b41a096ce61eb376f00cf03f28ea7688e9fc85d71e
|
|
BLAKE2b-256 checksum How to use checksums |
fa1c1b0737844ba80fd81dc8d3a256643d4ed33c1d2483c389564210363f425f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logSecurity for twittrapi-haystack 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for twittrapi_haystack-0.1.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 12, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.