xquik-haystack 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- haystack_integrations/components/websearch/py.typed +1 -0
- haystack_integrations/components/websearch/xquik/__init__.py +10 -0
- haystack_integrations/components/websearch/xquik/xquik_websearch.py +417 -0
- haystack_integrations/py.typed +0 -0
- xquik_haystack-0.1.0.dist-info/METADATA +124 -0
- xquik_haystack-0.1.0.dist-info/RECORD +8 -0
- xquik_haystack-0.1.0.dist-info/WHEEL +4 -0
- xquik_haystack-0.1.0.dist-info/licenses/LICENSE +201 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Xquik <support@xquik.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from haystack_integrations.components.websearch.xquik.xquik_websearch import (
|
|
6
|
+
XquikTweetSearch,
|
|
7
|
+
XquikUserTweetsFetcher,
|
|
8
|
+
)
|
|
9
|
+
|
|
10
|
+
__all__ = ["XquikTweetSearch", "XquikUserTweetsFetcher"]
|
|
@@ -0,0 +1,417 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026-present Xquik <support@xquik.com>
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
4
|
+
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
from collections.abc import Mapping
|
|
8
|
+
from typing import Any, Literal
|
|
9
|
+
from urllib.parse import quote
|
|
10
|
+
|
|
11
|
+
from haystack import Document, component, logging
|
|
12
|
+
from haystack.utils import Secret
|
|
13
|
+
from haystack.utils.requests_utils import async_request_with_retry, request_with_retry
|
|
14
|
+
|
|
15
|
+
logger = logging.getLogger(__name__)
|
|
16
|
+
|
|
17
|
+
XQUIK_API_URL = "https://xquik.com/api/v1"
|
|
18
|
+
XQUIK_API_CONTRACT = "2026-04-29"
|
|
19
|
+
|
|
20
|
+
QueryType = Literal["Latest", "Top"]
|
|
21
|
+
JsonObject = Mapping[str, Any]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
@component
|
|
25
|
+
class XquikTweetSearch:
|
|
26
|
+
"""
|
|
27
|
+
Search public X/Twitter posts with Xquik and return Haystack Documents.
|
|
28
|
+
|
|
29
|
+
The component calls `GET /x/tweets/search`, sends an `x-api-key` header, and opts in to the
|
|
30
|
+
current Xquik response contract. Unit tests should mock HTTP calls.
|
|
31
|
+
|
|
32
|
+
### Usage example
|
|
33
|
+
|
|
34
|
+
```python
|
|
35
|
+
from haystack.utils import Secret
|
|
36
|
+
from haystack_integrations.components.websearch.xquik import XquikTweetSearch
|
|
37
|
+
|
|
38
|
+
search = XquikTweetSearch(api_key=Secret.from_env_var("XQUIK_API_KEY"), top_k=10)
|
|
39
|
+
result = search.run(query="haystack ai")
|
|
40
|
+
documents = result["documents"]
|
|
41
|
+
```
|
|
42
|
+
"""
|
|
43
|
+
|
|
44
|
+
def __init__(
|
|
45
|
+
self,
|
|
46
|
+
api_key: Secret = Secret.from_env_var("XQUIK_API_KEY"),
|
|
47
|
+
top_k: int | None = 20,
|
|
48
|
+
query_type: QueryType = "Latest",
|
|
49
|
+
base_url: str = XQUIK_API_URL,
|
|
50
|
+
extra_params: dict[str, Any] | None = None,
|
|
51
|
+
timeout: int = 10,
|
|
52
|
+
max_retries: int = 3,
|
|
53
|
+
) -> None:
|
|
54
|
+
"""
|
|
55
|
+
Initialize the XquikTweetSearch component.
|
|
56
|
+
|
|
57
|
+
:param api_key:
|
|
58
|
+
Xquik API key. Defaults to the `XQUIK_API_KEY` environment variable.
|
|
59
|
+
:param top_k:
|
|
60
|
+
Maximum number of tweets to request. Maps to the Xquik `limit` query parameter.
|
|
61
|
+
:param query_type:
|
|
62
|
+
Xquik search ordering. Use `Latest` for chronological results or `Top` for engagement-ranked results.
|
|
63
|
+
:param base_url:
|
|
64
|
+
Base Xquik API URL. Defaults to `https://xquik.com/api/v1`.
|
|
65
|
+
:param extra_params:
|
|
66
|
+
Additional query parameters passed to the tweet search endpoint.
|
|
67
|
+
:param timeout:
|
|
68
|
+
Timeout in seconds for the HTTP request.
|
|
69
|
+
:param max_retries:
|
|
70
|
+
Maximum retry attempts for transient request failures.
|
|
71
|
+
"""
|
|
72
|
+
self.api_key = api_key
|
|
73
|
+
self.top_k = top_k
|
|
74
|
+
self.query_type = query_type
|
|
75
|
+
self.base_url = base_url.rstrip("/")
|
|
76
|
+
self.extra_params = extra_params
|
|
77
|
+
self.timeout = timeout
|
|
78
|
+
self.max_retries = max_retries
|
|
79
|
+
|
|
80
|
+
@component.output_types(documents=list[Document], links=list[str], has_more=bool, next_cursor=str | None)
|
|
81
|
+
def run(
|
|
82
|
+
self,
|
|
83
|
+
query: str,
|
|
84
|
+
top_k: int | None = None,
|
|
85
|
+
query_type: QueryType | None = None,
|
|
86
|
+
cursor: str | None = None,
|
|
87
|
+
since_time: str | None = None,
|
|
88
|
+
until_time: str | None = None,
|
|
89
|
+
) -> dict[str, Any]:
|
|
90
|
+
"""
|
|
91
|
+
Search public tweets and return Haystack Documents.
|
|
92
|
+
|
|
93
|
+
:param query:
|
|
94
|
+
X search query string, including standard X query operators.
|
|
95
|
+
:param top_k:
|
|
96
|
+
Optional per-run override for the maximum number of tweets.
|
|
97
|
+
:param query_type:
|
|
98
|
+
Optional per-run override for Xquik search ordering.
|
|
99
|
+
:param cursor:
|
|
100
|
+
Optional pagination cursor from a previous response.
|
|
101
|
+
:param since_time:
|
|
102
|
+
Optional ISO 8601 lower bound for tweet creation time.
|
|
103
|
+
:param until_time:
|
|
104
|
+
Optional ISO 8601 upper bound for tweet creation time.
|
|
105
|
+
:returns:
|
|
106
|
+
A dictionary with `documents`, `links`, `has_more`, and `next_cursor`.
|
|
107
|
+
"""
|
|
108
|
+
params = self._build_params(
|
|
109
|
+
query=query,
|
|
110
|
+
top_k=top_k,
|
|
111
|
+
query_type=query_type,
|
|
112
|
+
cursor=cursor,
|
|
113
|
+
since_time=since_time,
|
|
114
|
+
until_time=until_time,
|
|
115
|
+
)
|
|
116
|
+
response = request_with_retry(
|
|
117
|
+
attempts=self.max_retries,
|
|
118
|
+
method="GET",
|
|
119
|
+
url=f"{self.base_url}/x/tweets/search",
|
|
120
|
+
params=params,
|
|
121
|
+
headers=_build_headers(self.api_key),
|
|
122
|
+
timeout=self.timeout,
|
|
123
|
+
)
|
|
124
|
+
response.raise_for_status()
|
|
125
|
+
return _parse_tweets_response(response.json(), endpoint="x.tweets.search")
|
|
126
|
+
|
|
127
|
+
@component.output_types(documents=list[Document], links=list[str], has_more=bool, next_cursor=str | None)
|
|
128
|
+
async def run_async(
|
|
129
|
+
self,
|
|
130
|
+
query: str,
|
|
131
|
+
top_k: int | None = None,
|
|
132
|
+
query_type: QueryType | None = None,
|
|
133
|
+
cursor: str | None = None,
|
|
134
|
+
since_time: str | None = None,
|
|
135
|
+
until_time: str | None = None,
|
|
136
|
+
) -> dict[str, Any]:
|
|
137
|
+
"""
|
|
138
|
+
Asynchronously search public tweets and return Haystack Documents.
|
|
139
|
+
|
|
140
|
+
:param query:
|
|
141
|
+
X search query string, including standard X query operators.
|
|
142
|
+
:param top_k:
|
|
143
|
+
Optional per-run override for the maximum number of tweets.
|
|
144
|
+
:param query_type:
|
|
145
|
+
Optional per-run override for Xquik search ordering.
|
|
146
|
+
:param cursor:
|
|
147
|
+
Optional pagination cursor from a previous response.
|
|
148
|
+
:param since_time:
|
|
149
|
+
Optional ISO 8601 lower bound for tweet creation time.
|
|
150
|
+
:param until_time:
|
|
151
|
+
Optional ISO 8601 upper bound for tweet creation time.
|
|
152
|
+
:returns:
|
|
153
|
+
A dictionary with `documents`, `links`, `has_more`, and `next_cursor`.
|
|
154
|
+
"""
|
|
155
|
+
params = self._build_params(
|
|
156
|
+
query=query,
|
|
157
|
+
top_k=top_k,
|
|
158
|
+
query_type=query_type,
|
|
159
|
+
cursor=cursor,
|
|
160
|
+
since_time=since_time,
|
|
161
|
+
until_time=until_time,
|
|
162
|
+
)
|
|
163
|
+
response = await async_request_with_retry(
|
|
164
|
+
attempts=self.max_retries,
|
|
165
|
+
method="GET",
|
|
166
|
+
url=f"{self.base_url}/x/tweets/search",
|
|
167
|
+
params=params,
|
|
168
|
+
headers=_build_headers(self.api_key),
|
|
169
|
+
timeout=self.timeout,
|
|
170
|
+
)
|
|
171
|
+
response.raise_for_status()
|
|
172
|
+
return _parse_tweets_response(response.json(), endpoint="x.tweets.search")
|
|
173
|
+
|
|
174
|
+
def _build_params(
|
|
175
|
+
self,
|
|
176
|
+
query: str,
|
|
177
|
+
top_k: int | None,
|
|
178
|
+
query_type: QueryType | None,
|
|
179
|
+
cursor: str | None,
|
|
180
|
+
since_time: str | None,
|
|
181
|
+
until_time: str | None,
|
|
182
|
+
) -> dict[str, Any]:
|
|
183
|
+
effective_top_k = self.top_k if top_k is None else top_k
|
|
184
|
+
effective_query_type = self.query_type if query_type is None else query_type
|
|
185
|
+
params: dict[str, Any] = {"q": query, "queryType": effective_query_type}
|
|
186
|
+
if effective_top_k is not None:
|
|
187
|
+
params["limit"] = effective_top_k
|
|
188
|
+
if cursor is not None:
|
|
189
|
+
params["cursor"] = cursor
|
|
190
|
+
if since_time is not None:
|
|
191
|
+
params["sinceTime"] = since_time
|
|
192
|
+
if until_time is not None:
|
|
193
|
+
params["untilTime"] = until_time
|
|
194
|
+
if self.extra_params:
|
|
195
|
+
params.update(self.extra_params)
|
|
196
|
+
return params
|
|
197
|
+
|
|
198
|
+
|
|
199
|
+
@component
|
|
200
|
+
class XquikUserTweetsFetcher:
|
|
201
|
+
"""
|
|
202
|
+
Fetch recent public posts for a user with Xquik and return Haystack Documents.
|
|
203
|
+
|
|
204
|
+
The component calls `GET /x/users/{id}/tweets`, where `id` can be an X user ID or username.
|
|
205
|
+
Unit tests should mock HTTP calls.
|
|
206
|
+
"""
|
|
207
|
+
|
|
208
|
+
def __init__(
|
|
209
|
+
self,
|
|
210
|
+
api_key: Secret = Secret.from_env_var("XQUIK_API_KEY"),
|
|
211
|
+
include_replies: bool = False,
|
|
212
|
+
include_parent_tweet: bool = False,
|
|
213
|
+
base_url: str = XQUIK_API_URL,
|
|
214
|
+
timeout: int = 10,
|
|
215
|
+
max_retries: int = 3,
|
|
216
|
+
) -> None:
|
|
217
|
+
"""
|
|
218
|
+
Initialize the XquikUserTweetsFetcher component.
|
|
219
|
+
|
|
220
|
+
:param api_key:
|
|
221
|
+
Xquik API key. Defaults to the `XQUIK_API_KEY` environment variable.
|
|
222
|
+
:param include_replies:
|
|
223
|
+
Include reply tweets in the user timeline response.
|
|
224
|
+
:param include_parent_tweet:
|
|
225
|
+
Include parent tweet data for replies when available.
|
|
226
|
+
:param base_url:
|
|
227
|
+
Base Xquik API URL. Defaults to `https://xquik.com/api/v1`.
|
|
228
|
+
:param timeout:
|
|
229
|
+
Timeout in seconds for the HTTP request.
|
|
230
|
+
:param max_retries:
|
|
231
|
+
Maximum retry attempts for transient request failures.
|
|
232
|
+
"""
|
|
233
|
+
self.api_key = api_key
|
|
234
|
+
self.include_replies = include_replies
|
|
235
|
+
self.include_parent_tweet = include_parent_tweet
|
|
236
|
+
self.base_url = base_url.rstrip("/")
|
|
237
|
+
self.timeout = timeout
|
|
238
|
+
self.max_retries = max_retries
|
|
239
|
+
|
|
240
|
+
@component.output_types(documents=list[Document], links=list[str], has_more=bool, next_cursor=str | None)
|
|
241
|
+
def run(
|
|
242
|
+
self,
|
|
243
|
+
user_id: str,
|
|
244
|
+
cursor: str | None = None,
|
|
245
|
+
include_replies: bool | None = None,
|
|
246
|
+
include_parent_tweet: bool | None = None,
|
|
247
|
+
) -> dict[str, Any]:
|
|
248
|
+
"""
|
|
249
|
+
Fetch recent public tweets for a user and return Haystack Documents.
|
|
250
|
+
|
|
251
|
+
:param user_id:
|
|
252
|
+
X user ID or username.
|
|
253
|
+
:param cursor:
|
|
254
|
+
Optional pagination cursor from a previous response.
|
|
255
|
+
:param include_replies:
|
|
256
|
+
Optional per-run override for including replies.
|
|
257
|
+
:param include_parent_tweet:
|
|
258
|
+
Optional per-run override for including parent tweet data.
|
|
259
|
+
:returns:
|
|
260
|
+
A dictionary with `documents`, `links`, `has_more`, and `next_cursor`.
|
|
261
|
+
"""
|
|
262
|
+
params = self._build_params(
|
|
263
|
+
cursor=cursor,
|
|
264
|
+
include_replies=include_replies,
|
|
265
|
+
include_parent_tweet=include_parent_tweet,
|
|
266
|
+
)
|
|
267
|
+
response = request_with_retry(
|
|
268
|
+
attempts=self.max_retries,
|
|
269
|
+
method="GET",
|
|
270
|
+
url=f"{self.base_url}/x/users/{quote(user_id, safe='')}/tweets",
|
|
271
|
+
params=params,
|
|
272
|
+
headers=_build_headers(self.api_key),
|
|
273
|
+
timeout=self.timeout,
|
|
274
|
+
)
|
|
275
|
+
response.raise_for_status()
|
|
276
|
+
return _parse_tweets_response(response.json(), endpoint="x.users.tweets")
|
|
277
|
+
|
|
278
|
+
@component.output_types(documents=list[Document], links=list[str], has_more=bool, next_cursor=str | None)
|
|
279
|
+
async def run_async(
|
|
280
|
+
self,
|
|
281
|
+
user_id: str,
|
|
282
|
+
cursor: str | None = None,
|
|
283
|
+
include_replies: bool | None = None,
|
|
284
|
+
include_parent_tweet: bool | None = None,
|
|
285
|
+
) -> dict[str, Any]:
|
|
286
|
+
"""
|
|
287
|
+
Asynchronously fetch recent public tweets for a user and return Haystack Documents.
|
|
288
|
+
|
|
289
|
+
:param user_id:
|
|
290
|
+
X user ID or username.
|
|
291
|
+
:param cursor:
|
|
292
|
+
Optional pagination cursor from a previous response.
|
|
293
|
+
:param include_replies:
|
|
294
|
+
Optional per-run override for including replies.
|
|
295
|
+
:param include_parent_tweet:
|
|
296
|
+
Optional per-run override for including parent tweet data.
|
|
297
|
+
:returns:
|
|
298
|
+
A dictionary with `documents`, `links`, `has_more`, and `next_cursor`.
|
|
299
|
+
"""
|
|
300
|
+
params = self._build_params(
|
|
301
|
+
cursor=cursor,
|
|
302
|
+
include_replies=include_replies,
|
|
303
|
+
include_parent_tweet=include_parent_tweet,
|
|
304
|
+
)
|
|
305
|
+
response = await async_request_with_retry(
|
|
306
|
+
attempts=self.max_retries,
|
|
307
|
+
method="GET",
|
|
308
|
+
url=f"{self.base_url}/x/users/{quote(user_id, safe='')}/tweets",
|
|
309
|
+
params=params,
|
|
310
|
+
headers=_build_headers(self.api_key),
|
|
311
|
+
timeout=self.timeout,
|
|
312
|
+
)
|
|
313
|
+
response.raise_for_status()
|
|
314
|
+
return _parse_tweets_response(response.json(), endpoint="x.users.tweets")
|
|
315
|
+
|
|
316
|
+
def _build_params(
|
|
317
|
+
self,
|
|
318
|
+
cursor: str | None,
|
|
319
|
+
include_replies: bool | None,
|
|
320
|
+
include_parent_tweet: bool | None,
|
|
321
|
+
) -> dict[str, Any]:
|
|
322
|
+
params: dict[str, Any] = {
|
|
323
|
+
"includeReplies": self.include_replies if include_replies is None else include_replies,
|
|
324
|
+
"includeParentTweet": self.include_parent_tweet if include_parent_tweet is None else include_parent_tweet,
|
|
325
|
+
}
|
|
326
|
+
if cursor is not None:
|
|
327
|
+
params["cursor"] = cursor
|
|
328
|
+
return params
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
def _build_headers(api_key: Secret) -> dict[str, str]:
|
|
332
|
+
return {
|
|
333
|
+
"Accept": "application/json",
|
|
334
|
+
"x-api-key": api_key.resolve_value() or "",
|
|
335
|
+
"xquik-api-contract": XQUIK_API_CONTRACT,
|
|
336
|
+
}
|
|
337
|
+
|
|
338
|
+
|
|
339
|
+
def _parse_tweets_response(response: JsonObject, endpoint: str) -> dict[str, Any]:
|
|
340
|
+
documents: list[Document] = []
|
|
341
|
+
links: list[str] = []
|
|
342
|
+
|
|
343
|
+
tweets = _as_list(_get(response, "tweets", "data", default=[]))
|
|
344
|
+
for tweet in tweets:
|
|
345
|
+
if not isinstance(tweet, Mapping):
|
|
346
|
+
continue
|
|
347
|
+
document = _tweet_to_document(tweet, endpoint=endpoint)
|
|
348
|
+
documents.append(document)
|
|
349
|
+
url = document.meta.get("url")
|
|
350
|
+
if isinstance(url, str) and url:
|
|
351
|
+
links.append(url)
|
|
352
|
+
|
|
353
|
+
has_more = bool(_get(response, "has_more", "has_next_page", "hasMore", default=False))
|
|
354
|
+
next_cursor = _as_optional_string(_get(response, "next_cursor", "nextCursor", default=None))
|
|
355
|
+
return {"documents": documents, "links": links, "has_more": has_more, "next_cursor": next_cursor}
|
|
356
|
+
|
|
357
|
+
|
|
358
|
+
def _tweet_to_document(tweet: JsonObject, endpoint: str) -> Document:
|
|
359
|
+
content = _as_optional_string(_get(tweet, "text", "full_text", "content", default="")) or ""
|
|
360
|
+
meta: dict[str, Any] = {"endpoint": endpoint}
|
|
361
|
+
for key, aliases in {
|
|
362
|
+
"id": ("id",),
|
|
363
|
+
"url": ("url",),
|
|
364
|
+
"created_at": ("created_at", "createdAt"),
|
|
365
|
+
"lang": ("lang",),
|
|
366
|
+
"conversation_id": ("conversation_id", "conversationId"),
|
|
367
|
+
"in_reply_to_id": ("in_reply_to_id", "inReplyToId"),
|
|
368
|
+
"in_reply_to_user_id": ("in_reply_to_user_id", "inReplyToUserId"),
|
|
369
|
+
"in_reply_to_username": ("in_reply_to_username", "inReplyToUsername"),
|
|
370
|
+
"is_reply": ("is_reply", "isReply"),
|
|
371
|
+
"is_quote_status": ("is_quote_status", "isQuoteStatus"),
|
|
372
|
+
"like_count": ("like_count", "likeCount"),
|
|
373
|
+
"retweet_count": ("retweet_count", "retweetCount"),
|
|
374
|
+
"reply_count": ("reply_count", "replyCount"),
|
|
375
|
+
"quote_count": ("quote_count", "quoteCount"),
|
|
376
|
+
"view_count": ("view_count", "viewCount"),
|
|
377
|
+
"bookmark_count": ("bookmark_count", "bookmarkCount"),
|
|
378
|
+
}.items():
|
|
379
|
+
value = _get(tweet, *aliases, default=None)
|
|
380
|
+
if value is not None:
|
|
381
|
+
meta[key] = value
|
|
382
|
+
|
|
383
|
+
author = _get(tweet, "author", "user", default=None)
|
|
384
|
+
if isinstance(author, Mapping):
|
|
385
|
+
meta["author"] = _compact(
|
|
386
|
+
{
|
|
387
|
+
"id": _get(author, "id", default=None),
|
|
388
|
+
"username": _get(author, "username", "screen_name", default=None),
|
|
389
|
+
"name": _get(author, "name", default=None),
|
|
390
|
+
"verified": _get(author, "verified", default=None),
|
|
391
|
+
}
|
|
392
|
+
)
|
|
393
|
+
|
|
394
|
+
return Document(content=content, meta=meta)
|
|
395
|
+
|
|
396
|
+
|
|
397
|
+
def _get(data: JsonObject, *keys: str, default: Any) -> Any:
|
|
398
|
+
for key in keys:
|
|
399
|
+
if key in data:
|
|
400
|
+
return data[key]
|
|
401
|
+
return default
|
|
402
|
+
|
|
403
|
+
|
|
404
|
+
def _as_list(value: Any) -> list[Any]:
|
|
405
|
+
if isinstance(value, list):
|
|
406
|
+
return value
|
|
407
|
+
return []
|
|
408
|
+
|
|
409
|
+
|
|
410
|
+
def _as_optional_string(value: Any) -> str | None:
|
|
411
|
+
if value is None:
|
|
412
|
+
return None
|
|
413
|
+
return str(value)
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
def _compact(data: dict[str, Any]) -> dict[str, Any]:
|
|
417
|
+
return {key: value for key, value in data.items() if value is not None}
|
|
File without changes
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: xquik-haystack
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Haystack web search components for Xquik public X data
|
|
5
|
+
Project-URL: Documentation, https://docs.xquik.com/guides/haystack
|
|
6
|
+
Project-URL: Issues, https://github.com/Xquik-dev/xquik-haystack/issues
|
|
7
|
+
Project-URL: Source, https://github.com/Xquik-dev/xquik-haystack
|
|
8
|
+
Author-email: Xquik <support@xquik.com>
|
|
9
|
+
License-Expression: Apache-2.0
|
|
10
|
+
License-File: LICENSE
|
|
11
|
+
Keywords: haystack,retrieval,social-media,twitter,websearch,x,xquik
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
15
|
+
Classifier: Programming Language :: Python
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
21
|
+
Classifier: Programming Language :: Python :: Implementation :: CPython
|
|
22
|
+
Classifier: Programming Language :: Python :: Implementation :: PyPy
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Requires-Dist: haystack-ai
|
|
25
|
+
Requires-Dist: httpx>=0.24
|
|
26
|
+
Description-Content-Type: text/markdown
|
|
27
|
+
|
|
28
|
+
# Xquik Haystack
|
|
29
|
+
|
|
30
|
+
Haystack web search components for retrieving public X/Twitter context through the Xquik REST API.
|
|
31
|
+
|
|
32
|
+
Documentation: <https://docs.xquik.com/guides/haystack>
|
|
33
|
+
|
|
34
|
+
This package is maintained by Xquik as a standalone Haystack integration. It follows the `haystack_integrations` namespace convention and exposes read-only components under:
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from haystack_integrations.components.websearch.xquik import XquikTweetSearch, XquikUserTweetsFetcher
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
## Components
|
|
41
|
+
|
|
42
|
+
- `XquikTweetSearch`: calls `GET /x/tweets/search` and returns matching posts as Haystack `Document` objects.
|
|
43
|
+
- `XquikUserTweetsFetcher`: calls `GET /x/users/{id}/tweets` and returns recent public posts for a user as Haystack `Document` objects.
|
|
44
|
+
|
|
45
|
+
Both components:
|
|
46
|
+
|
|
47
|
+
- read the API key from `XQUIK_API_KEY` by default
|
|
48
|
+
- accept `haystack.utils.Secret` for explicit API key injection
|
|
49
|
+
- send the `x-api-key` and `xquik-api-contract: 2026-04-29` headers
|
|
50
|
+
- keep `base_url` configurable for tests and controlled deployments
|
|
51
|
+
- return `documents`, `links`, `has_more`, and `next_cursor`
|
|
52
|
+
|
|
53
|
+
## Installation
|
|
54
|
+
|
|
55
|
+
Install from PyPI:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
pip install xquik-haystack
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
## Usage
|
|
62
|
+
|
|
63
|
+
### Tweet Search
|
|
64
|
+
|
|
65
|
+
```python
|
|
66
|
+
from haystack import Pipeline
|
|
67
|
+
from haystack.utils import Secret
|
|
68
|
+
from haystack_integrations.components.websearch.xquik import XquikTweetSearch
|
|
69
|
+
|
|
70
|
+
search = XquikTweetSearch(api_key=Secret.from_env_var("XQUIK_API_KEY"), top_k=10)
|
|
71
|
+
|
|
72
|
+
pipeline = Pipeline()
|
|
73
|
+
pipeline.add_component("x_search", search)
|
|
74
|
+
|
|
75
|
+
result = pipeline.run({"x_search": {"query": "haystack ai"}})
|
|
76
|
+
documents = result["x_search"]["documents"]
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### User Tweets
|
|
80
|
+
|
|
81
|
+
```python
|
|
82
|
+
from haystack.utils import Secret
|
|
83
|
+
from haystack_integrations.components.websearch.xquik import XquikUserTweetsFetcher
|
|
84
|
+
|
|
85
|
+
fetcher = XquikUserTweetsFetcher(api_key=Secret.from_env_var("XQUIK_API_KEY"))
|
|
86
|
+
|
|
87
|
+
result = fetcher.run(user_id="xquikcom", include_replies=False)
|
|
88
|
+
documents = result["documents"]
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
## Document Mapping
|
|
92
|
+
|
|
93
|
+
Each tweet becomes a Haystack `Document`.
|
|
94
|
+
|
|
95
|
+
- `Document.content`: tweet text, or an empty string when text is missing
|
|
96
|
+
- `Document.meta["endpoint"]`: Xquik endpoint family used by the component
|
|
97
|
+
- `Document.meta["id"]`: tweet ID when present
|
|
98
|
+
- `Document.meta["url"]`: tweet URL when present
|
|
99
|
+
- `Document.meta["created_at"]`: tweet creation time when present
|
|
100
|
+
- `Document.meta["author"]`: author ID, username, display name, and verification status when present
|
|
101
|
+
- `Document.meta` also includes available public metrics such as like, repost, reply, quote, view, and bookmark counts
|
|
102
|
+
|
|
103
|
+
## Development
|
|
104
|
+
|
|
105
|
+
This project uses [Hatch](https://hatch.pypa.io/) for build and environment management.
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
pip install hatch
|
|
109
|
+
hatch run fmt-check
|
|
110
|
+
hatch run test:unit
|
|
111
|
+
hatch build
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
Unit tests mock all Xquik HTTP calls. Integration tests can be added later behind an `XQUIK_API_KEY` check.
|
|
115
|
+
|
|
116
|
+
## Publishing
|
|
117
|
+
|
|
118
|
+
The release workflow publishes to PyPI with trusted publishing when a GitHub release is published.
|
|
119
|
+
|
|
120
|
+
After a first PyPI version is published, submit a listing PR to [`deepset-ai/haystack-integrations`](https://github.com/deepset-ai/haystack-integrations) as requested by the Haystack maintainers.
|
|
121
|
+
|
|
122
|
+
## License
|
|
123
|
+
|
|
124
|
+
`xquik-haystack` is distributed under the terms of the [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html) license.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
haystack_integrations/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
haystack_integrations/components/websearch/py.typed,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
|
|
3
|
+
haystack_integrations/components/websearch/xquik/__init__.py,sha256=-f48GWmlFDcPMjRBSQQqgOyl0nBRponHnmNmSrd7qCc,295
|
|
4
|
+
haystack_integrations/components/websearch/xquik/xquik_websearch.py,sha256=az2ntrVCGcKkB3qd8656lZhmD7mzo-TqqmgIqds0XM4,15232
|
|
5
|
+
xquik_haystack-0.1.0.dist-info/METADATA,sha256=tc13Xo3kq0237B-8PijPoO8WkJiKAW5yLe6-B9-1-RY,4437
|
|
6
|
+
xquik_haystack-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
|
|
7
|
+
xquik_haystack-0.1.0.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
|
|
8
|
+
xquik_haystack-0.1.0.dist-info/RECORD,,
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
179
|
+
|
|
180
|
+
To apply the Apache License to your work, attach the following
|
|
181
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
182
|
+
replaced with your own identifying information. (Don't include
|
|
183
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
184
|
+
comment syntax for the file format. We also recommend that a
|
|
185
|
+
file or class name and description of purpose be included on the
|
|
186
|
+
same "printed page" as the copyright notice for easier
|
|
187
|
+
identification within third-party archives.
|
|
188
|
+
|
|
189
|
+
Copyright [yyyy] [name of copyright owner]
|
|
190
|
+
|
|
191
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
192
|
+
you may not use this file except in compliance with the License.
|
|
193
|
+
You may obtain a copy of the License at
|
|
194
|
+
|
|
195
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
196
|
+
|
|
197
|
+
Unless required by applicable law or agreed to in writing, software
|
|
198
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
199
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
200
|
+
See the License for the specific language governing permissions and
|
|
201
|
+
limitations under the License.
|