xdataapi 0.3.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.
Files changed (61) hide show
  1. xdataapi/__init__.py +8 -0
  2. xdataapi/api/__init__.py +1 -0
  3. xdataapi/api/account/__init__.py +1 -0
  4. xdataapi/api/account/get_me.py +144 -0
  5. xdataapi/api/billing/__init__.py +1 -0
  6. xdataapi/api/billing/create_checkout.py +206 -0
  7. xdataapi/api/billing/list_packs.py +144 -0
  8. xdataapi/api/tweets/__init__.py +1 -0
  9. xdataapi/api/tweets/get_quotes.py +241 -0
  10. xdataapi/api/tweets/get_replies.py +230 -0
  11. xdataapi/api/tweets/get_retweeters.py +245 -0
  12. xdataapi/api/tweets/get_thread.py +226 -0
  13. xdataapi/api/tweets/get_tweet.py +213 -0
  14. xdataapi/api/tweets/get_tweets.py +223 -0
  15. xdataapi/api/tweets/search_tweets.py +277 -0
  16. xdataapi/api/users/__init__.py +1 -0
  17. xdataapi/api/users/get_follower_ids.py +254 -0
  18. xdataapi/api/users/get_followers.py +254 -0
  19. xdataapi/api/users/get_following.py +246 -0
  20. xdataapi/api/users/get_user.py +213 -0
  21. xdataapi/api/users/get_user_tweets.py +241 -0
  22. xdataapi/api/users/get_users.py +231 -0
  23. xdataapi/client.py +268 -0
  24. xdataapi/errors.py +16 -0
  25. xdataapi/models/__init__.py +67 -0
  26. xdataapi/models/batch_error.py +79 -0
  27. xdataapi/models/batch_error_code.py +15 -0
  28. xdataapi/models/batch_meta.py +126 -0
  29. xdataapi/models/batch_meta_cache.py +11 -0
  30. xdataapi/models/create_checkout_body.py +63 -0
  31. xdataapi/models/create_checkout_body_pack.py +11 -0
  32. xdataapi/models/create_checkout_response_200.py +97 -0
  33. xdataapi/models/error.py +78 -0
  34. xdataapi/models/error_body.py +72 -0
  35. xdataapi/models/error_body_code.py +22 -0
  36. xdataapi/models/get_me_response_200.py +88 -0
  37. xdataapi/models/get_tweets_body.py +61 -0
  38. xdataapi/models/get_users_body.py +61 -0
  39. xdataapi/models/id_page.py +117 -0
  40. xdataapi/models/list_packs_response_200.py +105 -0
  41. xdataapi/models/list_packs_response_200_data_item.py +88 -0
  42. xdataapi/models/list_packs_response_200_rate_limits_item.py +70 -0
  43. xdataapi/models/media.py +96 -0
  44. xdataapi/models/media_type.py +10 -0
  45. xdataapi/models/meta.py +106 -0
  46. xdataapi/models/meta_cache.py +10 -0
  47. xdataapi/models/problem.py +131 -0
  48. xdataapi/models/search_tweets_product.py +12 -0
  49. xdataapi/models/tweet.py +310 -0
  50. xdataapi/models/tweet_batch.py +150 -0
  51. xdataapi/models/tweet_page.py +133 -0
  52. xdataapi/models/tweet_response.py +128 -0
  53. xdataapi/models/user.py +204 -0
  54. xdataapi/models/user_batch.py +150 -0
  55. xdataapi/models/user_page.py +133 -0
  56. xdataapi/models/user_response.py +128 -0
  57. xdataapi/py.typed +1 -0
  58. xdataapi/types.py +54 -0
  59. xdataapi-0.3.0.dist-info/METADATA +148 -0
  60. xdataapi-0.3.0.dist-info/RECORD +61 -0
  61. xdataapi-0.3.0.dist-info/WHEEL +4 -0
@@ -0,0 +1,277 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+
4
+ import httpx
5
+
6
+ from ... import errors
7
+ from ...client import AuthenticatedClient, Client
8
+ from ...models.error import Error
9
+ from ...models.search_tweets_product import SearchTweetsProduct
10
+ from ...models.tweet_page import TweetPage
11
+ from ...types import UNSET, Response, Unset
12
+
13
+
14
+ def _get_kwargs(
15
+ *,
16
+ q: str,
17
+ product: SearchTweetsProduct | Unset = SearchTweetsProduct.LATEST,
18
+ count: int | Unset = 20,
19
+ cursor: str | Unset = UNSET,
20
+ fresh: bool | Unset = False,
21
+ ) -> dict[str, Any]:
22
+
23
+ params: dict[str, Any] = {}
24
+
25
+ params["q"] = q
26
+
27
+ json_product: str | Unset = UNSET
28
+ if not isinstance(product, Unset):
29
+ json_product = product.value
30
+
31
+ params["product"] = json_product
32
+
33
+ params["count"] = count
34
+
35
+ params["cursor"] = cursor
36
+
37
+ params["fresh"] = fresh
38
+
39
+ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
40
+
41
+ _kwargs: dict[str, Any] = {
42
+ "method": "get",
43
+ "url": "/v1/tweets/search",
44
+ "params": params,
45
+ }
46
+
47
+ return _kwargs
48
+
49
+
50
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Error | TweetPage | None:
51
+ if response.status_code == 200:
52
+ response_200 = TweetPage.from_dict(response.json())
53
+
54
+ return response_200
55
+
56
+ if response.status_code == 400:
57
+ response_400 = Error.from_dict(response.json())
58
+
59
+ return response_400
60
+
61
+ if response.status_code == 401:
62
+ response_401 = Error.from_dict(response.json())
63
+
64
+ return response_401
65
+
66
+ if response.status_code == 402:
67
+ response_402 = Error.from_dict(response.json())
68
+
69
+ return response_402
70
+
71
+ if response.status_code == 403:
72
+ response_403 = Error.from_dict(response.json())
73
+
74
+ return response_403
75
+
76
+ if response.status_code == 429:
77
+ response_429 = Error.from_dict(response.json())
78
+
79
+ return response_429
80
+
81
+ if response.status_code == 500:
82
+ response_500 = Error.from_dict(response.json())
83
+
84
+ return response_500
85
+
86
+ if response.status_code == 503:
87
+ response_503 = Error.from_dict(response.json())
88
+
89
+ return response_503
90
+
91
+ if client.raise_on_unexpected_status:
92
+ raise errors.UnexpectedStatus(response.status_code, response.content)
93
+ else:
94
+ return None
95
+
96
+
97
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Error | TweetPage]:
98
+ return Response(
99
+ status_code=HTTPStatus(response.status_code),
100
+ content=response.content,
101
+ headers=response.headers,
102
+ parsed=_parse_response(client=client, response=response),
103
+ )
104
+
105
+
106
+ def sync_detailed(
107
+ *,
108
+ client: AuthenticatedClient | Client,
109
+ q: str,
110
+ product: SearchTweetsProduct | Unset = SearchTweetsProduct.LATEST,
111
+ count: int | Unset = 20,
112
+ cursor: str | Unset = UNSET,
113
+ fresh: bool | Unset = False,
114
+ ) -> Response[Error | TweetPage]:
115
+ """Advanced search
116
+
117
+ 1 credit per tweet, or per profile with `product=People` (then `data` is a list of User).
118
+ `q` accepts X advanced search operators (from:, since:, until:, min_faves:, -filter:replies ...).
119
+ `product=Top` is not served to every reading session at X; when it is not, the response is HTTP 403
120
+ `product_unavailable` and nothing is charged. `Latest` is always available.
121
+
122
+ Args:
123
+ q (str):
124
+ product (SearchTweetsProduct | Unset): Default: SearchTweetsProduct.LATEST.
125
+ count (int | Unset): Default: 20.
126
+ cursor (str | Unset):
127
+ fresh (bool | Unset): Default: False.
128
+
129
+ Raises:
130
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
131
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
132
+
133
+ Returns:
134
+ Response[Error | TweetPage]
135
+ """
136
+
137
+ kwargs = _get_kwargs(
138
+ q=q,
139
+ product=product,
140
+ count=count,
141
+ cursor=cursor,
142
+ fresh=fresh,
143
+ )
144
+
145
+ response = client.get_httpx_client().request(
146
+ **kwargs,
147
+ )
148
+
149
+ return _build_response(client=client, response=response)
150
+
151
+
152
+ def sync(
153
+ *,
154
+ client: AuthenticatedClient | Client,
155
+ q: str,
156
+ product: SearchTweetsProduct | Unset = SearchTweetsProduct.LATEST,
157
+ count: int | Unset = 20,
158
+ cursor: str | Unset = UNSET,
159
+ fresh: bool | Unset = False,
160
+ ) -> Error | TweetPage | None:
161
+ """Advanced search
162
+
163
+ 1 credit per tweet, or per profile with `product=People` (then `data` is a list of User).
164
+ `q` accepts X advanced search operators (from:, since:, until:, min_faves:, -filter:replies ...).
165
+ `product=Top` is not served to every reading session at X; when it is not, the response is HTTP 403
166
+ `product_unavailable` and nothing is charged. `Latest` is always available.
167
+
168
+ Args:
169
+ q (str):
170
+ product (SearchTweetsProduct | Unset): Default: SearchTweetsProduct.LATEST.
171
+ count (int | Unset): Default: 20.
172
+ cursor (str | Unset):
173
+ fresh (bool | Unset): Default: False.
174
+
175
+ Raises:
176
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
177
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
178
+
179
+ Returns:
180
+ Error | TweetPage
181
+ """
182
+
183
+ return sync_detailed(
184
+ client=client,
185
+ q=q,
186
+ product=product,
187
+ count=count,
188
+ cursor=cursor,
189
+ fresh=fresh,
190
+ ).parsed
191
+
192
+
193
+ async def asyncio_detailed(
194
+ *,
195
+ client: AuthenticatedClient | Client,
196
+ q: str,
197
+ product: SearchTweetsProduct | Unset = SearchTweetsProduct.LATEST,
198
+ count: int | Unset = 20,
199
+ cursor: str | Unset = UNSET,
200
+ fresh: bool | Unset = False,
201
+ ) -> Response[Error | TweetPage]:
202
+ """Advanced search
203
+
204
+ 1 credit per tweet, or per profile with `product=People` (then `data` is a list of User).
205
+ `q` accepts X advanced search operators (from:, since:, until:, min_faves:, -filter:replies ...).
206
+ `product=Top` is not served to every reading session at X; when it is not, the response is HTTP 403
207
+ `product_unavailable` and nothing is charged. `Latest` is always available.
208
+
209
+ Args:
210
+ q (str):
211
+ product (SearchTweetsProduct | Unset): Default: SearchTweetsProduct.LATEST.
212
+ count (int | Unset): Default: 20.
213
+ cursor (str | Unset):
214
+ fresh (bool | Unset): Default: False.
215
+
216
+ Raises:
217
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
218
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
219
+
220
+ Returns:
221
+ Response[Error | TweetPage]
222
+ """
223
+
224
+ kwargs = _get_kwargs(
225
+ q=q,
226
+ product=product,
227
+ count=count,
228
+ cursor=cursor,
229
+ fresh=fresh,
230
+ )
231
+
232
+ response = await client.get_async_httpx_client().request(**kwargs)
233
+
234
+ return _build_response(client=client, response=response)
235
+
236
+
237
+ async def asyncio(
238
+ *,
239
+ client: AuthenticatedClient | Client,
240
+ q: str,
241
+ product: SearchTweetsProduct | Unset = SearchTweetsProduct.LATEST,
242
+ count: int | Unset = 20,
243
+ cursor: str | Unset = UNSET,
244
+ fresh: bool | Unset = False,
245
+ ) -> Error | TweetPage | None:
246
+ """Advanced search
247
+
248
+ 1 credit per tweet, or per profile with `product=People` (then `data` is a list of User).
249
+ `q` accepts X advanced search operators (from:, since:, until:, min_faves:, -filter:replies ...).
250
+ `product=Top` is not served to every reading session at X; when it is not, the response is HTTP 403
251
+ `product_unavailable` and nothing is charged. `Latest` is always available.
252
+
253
+ Args:
254
+ q (str):
255
+ product (SearchTweetsProduct | Unset): Default: SearchTweetsProduct.LATEST.
256
+ count (int | Unset): Default: 20.
257
+ cursor (str | Unset):
258
+ fresh (bool | Unset): Default: False.
259
+
260
+ Raises:
261
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
262
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
263
+
264
+ Returns:
265
+ Error | TweetPage
266
+ """
267
+
268
+ return (
269
+ await asyncio_detailed(
270
+ client=client,
271
+ q=q,
272
+ product=product,
273
+ count=count,
274
+ cursor=cursor,
275
+ fresh=fresh,
276
+ )
277
+ ).parsed
@@ -0,0 +1 @@
1
+ """Contains endpoint functions for accessing the API"""
@@ -0,0 +1,254 @@
1
+ from http import HTTPStatus
2
+ from typing import Any
3
+ from urllib.parse import quote
4
+
5
+ import httpx
6
+
7
+ from ... import errors
8
+ from ...client import AuthenticatedClient, Client
9
+ from ...models.error import Error
10
+ from ...models.id_page import IdPage
11
+ from ...types import UNSET, Response, Unset
12
+
13
+
14
+ def _get_kwargs(
15
+ user: str,
16
+ *,
17
+ count: int | Unset = 200,
18
+ cursor: str | Unset = UNSET,
19
+ fresh: bool | Unset = False,
20
+ ) -> dict[str, Any]:
21
+
22
+ params: dict[str, Any] = {}
23
+
24
+ params["count"] = count
25
+
26
+ params["cursor"] = cursor
27
+
28
+ params["fresh"] = fresh
29
+
30
+ params = {k: v for k, v in params.items() if v is not UNSET and v is not None}
31
+
32
+ _kwargs: dict[str, Any] = {
33
+ "method": "get",
34
+ "url": "/v1/users/{user}/followers/ids".format(
35
+ user=quote(str(user), safe=""),
36
+ ),
37
+ "params": params,
38
+ }
39
+
40
+ return _kwargs
41
+
42
+
43
+ def _parse_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Error | IdPage | None:
44
+ if response.status_code == 200:
45
+ response_200 = IdPage.from_dict(response.json())
46
+
47
+ return response_200
48
+
49
+ if response.status_code == 401:
50
+ response_401 = Error.from_dict(response.json())
51
+
52
+ return response_401
53
+
54
+ if response.status_code == 402:
55
+ response_402 = Error.from_dict(response.json())
56
+
57
+ return response_402
58
+
59
+ if response.status_code == 403:
60
+ response_403 = Error.from_dict(response.json())
61
+
62
+ return response_403
63
+
64
+ if response.status_code == 404:
65
+ response_404 = Error.from_dict(response.json())
66
+
67
+ return response_404
68
+
69
+ if response.status_code == 429:
70
+ response_429 = Error.from_dict(response.json())
71
+
72
+ return response_429
73
+
74
+ if response.status_code == 500:
75
+ response_500 = Error.from_dict(response.json())
76
+
77
+ return response_500
78
+
79
+ if response.status_code == 503:
80
+ response_503 = Error.from_dict(response.json())
81
+
82
+ return response_503
83
+
84
+ if client.raise_on_unexpected_status:
85
+ raise errors.UnexpectedStatus(response.status_code, response.content)
86
+ else:
87
+ return None
88
+
89
+
90
+ def _build_response(*, client: AuthenticatedClient | Client, response: httpx.Response) -> Response[Error | IdPage]:
91
+ return Response(
92
+ status_code=HTTPStatus(response.status_code),
93
+ content=response.content,
94
+ headers=response.headers,
95
+ parsed=_parse_response(client=client, response=response),
96
+ )
97
+
98
+
99
+ def sync_detailed(
100
+ user: str,
101
+ *,
102
+ client: AuthenticatedClient | Client,
103
+ count: int | Unset = 200,
104
+ cursor: str | Unset = UNSET,
105
+ fresh: bool | Unset = False,
106
+ ) -> Response[Error | IdPage]:
107
+ """Follower ids of a user
108
+
109
+ Numeric user ids only, no profiles. 0.02 credit per id. Up to 200 per page.
110
+ It is the same page `/followers` reads, so a page fetched through either endpoint is a cache
111
+ hit for the other, at half price. Same availability note as followers.
112
+
113
+ Args:
114
+ user (str):
115
+ count (int | Unset): Default: 200.
116
+ cursor (str | Unset):
117
+ fresh (bool | Unset): Default: False.
118
+
119
+ Raises:
120
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
121
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
122
+
123
+ Returns:
124
+ Response[Error | IdPage]
125
+ """
126
+
127
+ kwargs = _get_kwargs(
128
+ user=user,
129
+ count=count,
130
+ cursor=cursor,
131
+ fresh=fresh,
132
+ )
133
+
134
+ response = client.get_httpx_client().request(
135
+ **kwargs,
136
+ )
137
+
138
+ return _build_response(client=client, response=response)
139
+
140
+
141
+ def sync(
142
+ user: str,
143
+ *,
144
+ client: AuthenticatedClient | Client,
145
+ count: int | Unset = 200,
146
+ cursor: str | Unset = UNSET,
147
+ fresh: bool | Unset = False,
148
+ ) -> Error | IdPage | None:
149
+ """Follower ids of a user
150
+
151
+ Numeric user ids only, no profiles. 0.02 credit per id. Up to 200 per page.
152
+ It is the same page `/followers` reads, so a page fetched through either endpoint is a cache
153
+ hit for the other, at half price. Same availability note as followers.
154
+
155
+ Args:
156
+ user (str):
157
+ count (int | Unset): Default: 200.
158
+ cursor (str | Unset):
159
+ fresh (bool | Unset): Default: False.
160
+
161
+ Raises:
162
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
163
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
164
+
165
+ Returns:
166
+ Error | IdPage
167
+ """
168
+
169
+ return sync_detailed(
170
+ user=user,
171
+ client=client,
172
+ count=count,
173
+ cursor=cursor,
174
+ fresh=fresh,
175
+ ).parsed
176
+
177
+
178
+ async def asyncio_detailed(
179
+ user: str,
180
+ *,
181
+ client: AuthenticatedClient | Client,
182
+ count: int | Unset = 200,
183
+ cursor: str | Unset = UNSET,
184
+ fresh: bool | Unset = False,
185
+ ) -> Response[Error | IdPage]:
186
+ """Follower ids of a user
187
+
188
+ Numeric user ids only, no profiles. 0.02 credit per id. Up to 200 per page.
189
+ It is the same page `/followers` reads, so a page fetched through either endpoint is a cache
190
+ hit for the other, at half price. Same availability note as followers.
191
+
192
+ Args:
193
+ user (str):
194
+ count (int | Unset): Default: 200.
195
+ cursor (str | Unset):
196
+ fresh (bool | Unset): Default: False.
197
+
198
+ Raises:
199
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
200
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
201
+
202
+ Returns:
203
+ Response[Error | IdPage]
204
+ """
205
+
206
+ kwargs = _get_kwargs(
207
+ user=user,
208
+ count=count,
209
+ cursor=cursor,
210
+ fresh=fresh,
211
+ )
212
+
213
+ response = await client.get_async_httpx_client().request(**kwargs)
214
+
215
+ return _build_response(client=client, response=response)
216
+
217
+
218
+ async def asyncio(
219
+ user: str,
220
+ *,
221
+ client: AuthenticatedClient | Client,
222
+ count: int | Unset = 200,
223
+ cursor: str | Unset = UNSET,
224
+ fresh: bool | Unset = False,
225
+ ) -> Error | IdPage | None:
226
+ """Follower ids of a user
227
+
228
+ Numeric user ids only, no profiles. 0.02 credit per id. Up to 200 per page.
229
+ It is the same page `/followers` reads, so a page fetched through either endpoint is a cache
230
+ hit for the other, at half price. Same availability note as followers.
231
+
232
+ Args:
233
+ user (str):
234
+ count (int | Unset): Default: 200.
235
+ cursor (str | Unset):
236
+ fresh (bool | Unset): Default: False.
237
+
238
+ Raises:
239
+ errors.UnexpectedStatus: If the server returns an undocumented status code and Client.raise_on_unexpected_status is True.
240
+ httpx.TimeoutException: If the request takes longer than Client.timeout.
241
+
242
+ Returns:
243
+ Error | IdPage
244
+ """
245
+
246
+ return (
247
+ await asyncio_detailed(
248
+ user=user,
249
+ client=client,
250
+ count=count,
251
+ cursor=cursor,
252
+ fresh=fresh,
253
+ )
254
+ ).parsed