twitter-openapi-python 0.1.3__py3-none-any.whl → 0.1.5__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.
- twitter_openapi_python/api/birdwatch_api.py +1 -1
- twitter_openapi_python/api/community_api.py +1 -1
- twitter_openapi_python/api/default_api.py +1 -1
- twitter_openapi_python/api/post_api.py +1 -1
- twitter_openapi_python/api/tweet_api.py +1 -1
- twitter_openapi_python/api/user_api.py +2 -1
- twitter_openapi_python/api/user_list_api.py +1 -1
- twitter_openapi_python/api/users_api.py +2 -1
- twitter_openapi_python/client.py +15 -3
- twitter_openapi_python/utils/api.py +7 -5
- {twitter_openapi_python-0.1.3.dist-info → twitter_openapi_python-0.1.5.dist-info}/METADATA +13 -2
- {twitter_openapi_python-0.1.3.dist-info → twitter_openapi_python-0.1.5.dist-info}/RECORD +15 -15
- {twitter_openapi_python-0.1.3.dist-info → twitter_openapi_python-0.1.5.dist-info}/WHEEL +1 -1
- {twitter_openapi_python-0.1.3.dist-info → twitter_openapi_python-0.1.5.dist-info}/licenses/LICENSE +0 -0
- {twitter_openapi_python-0.1.3.dist-info → twitter_openapi_python-0.1.5.dist-info}/licenses/LICENSE.AGPL +0 -0
|
@@ -26,7 +26,7 @@ class BirdwatchApiUtils:
|
|
|
26
26
|
api: twitter.BirdwatchApi
|
|
27
27
|
flag: ParamType
|
|
28
28
|
|
|
29
|
-
def __init__(self, api: twitter.BirdwatchApi, flag: ParamType, ct: ClientTransaction):
|
|
29
|
+
def __init__(self, api: twitter.BirdwatchApi, flag: ParamType, ct: Optional[ClientTransaction]):
|
|
30
30
|
self.api = api
|
|
31
31
|
self.flag = flag
|
|
32
32
|
self.ct = ct
|
|
@@ -24,7 +24,7 @@ class CommunityApiUtils:
|
|
|
24
24
|
api: twitter.CommunityApi
|
|
25
25
|
flag: ParamType
|
|
26
26
|
|
|
27
|
-
def __init__(self, api: twitter.CommunityApi, flag: ParamType, ct: ClientTransaction):
|
|
27
|
+
def __init__(self, api: twitter.CommunityApi, flag: ParamType, ct: Optional[ClientTransaction]):
|
|
28
28
|
self.api = api
|
|
29
29
|
self.flag = flag
|
|
30
30
|
self.ct = ct
|
|
@@ -22,7 +22,7 @@ class DefaultApiUtils:
|
|
|
22
22
|
api: twitter.DefaultApi
|
|
23
23
|
flag: ParamType
|
|
24
24
|
|
|
25
|
-
def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: ClientTransaction):
|
|
25
|
+
def __init__(self, api: twitter.DefaultApi, flag: ParamType, ct: Optional[ClientTransaction]):
|
|
26
26
|
self.api = api
|
|
27
27
|
self.flag = flag
|
|
28
28
|
self.ct = ct
|
|
@@ -17,7 +17,7 @@ class PostApiUtils:
|
|
|
17
17
|
api: twitter.PostApi
|
|
18
18
|
flag: ParamType
|
|
19
19
|
|
|
20
|
-
def __init__(self, api: twitter.PostApi, flag: ParamType, ct: ClientTransaction):
|
|
20
|
+
def __init__(self, api: twitter.PostApi, flag: ParamType, ct: Optional[ClientTransaction]):
|
|
21
21
|
self.api = api
|
|
22
22
|
self.flag = flag
|
|
23
23
|
self.ct = ct
|
|
@@ -36,7 +36,7 @@ class TweetApiUtils:
|
|
|
36
36
|
api: twitter.TweetApi
|
|
37
37
|
flag: ParamType
|
|
38
38
|
|
|
39
|
-
def __init__(self, api: twitter.TweetApi, flag: ParamType, ct: ClientTransaction):
|
|
39
|
+
def __init__(self, api: twitter.TweetApi, flag: ParamType, ct: Optional[ClientTransaction]):
|
|
40
40
|
self.api = api
|
|
41
41
|
self.flag = flag
|
|
42
42
|
self.ct = ct
|
|
@@ -23,7 +23,7 @@ class UserApiUtils:
|
|
|
23
23
|
api: twitter.UserApi
|
|
24
24
|
flag: ParamType
|
|
25
25
|
|
|
26
|
-
def __init__(self, api: twitter.UserApi, flag: ParamType, ct: ClientTransaction):
|
|
26
|
+
def __init__(self, api: twitter.UserApi, flag: ParamType, ct: Optional[ClientTransaction]):
|
|
27
27
|
self.api = api
|
|
28
28
|
self.flag = flag
|
|
29
29
|
self.ct = ct
|
|
@@ -70,6 +70,7 @@ class UserApiUtils:
|
|
|
70
70
|
user_id: str,
|
|
71
71
|
extra_param: Optional[ParamType] = None,
|
|
72
72
|
) -> ResponseType:
|
|
73
|
+
"""Deprecated: X answers 403 outside a browser since 2026-10."""
|
|
73
74
|
param: ParamType = {"userId": user_id}
|
|
74
75
|
if extra_param is not None:
|
|
75
76
|
param.update(extra_param)
|
|
@@ -29,7 +29,7 @@ class UserListApiUtils:
|
|
|
29
29
|
api: twitter.UserListApi
|
|
30
30
|
flag: ParamType
|
|
31
31
|
|
|
32
|
-
def __init__(self, api: twitter.UserListApi, flag: ParamType, ct: ClientTransaction):
|
|
32
|
+
def __init__(self, api: twitter.UserListApi, flag: ParamType, ct: Optional[ClientTransaction]):
|
|
33
33
|
self.api = api
|
|
34
34
|
self.flag = flag
|
|
35
35
|
self.ct = ct
|
|
@@ -23,7 +23,7 @@ class UsersApiUtils:
|
|
|
23
23
|
api: twitter.UsersApi
|
|
24
24
|
flag: ParamType
|
|
25
25
|
|
|
26
|
-
def __init__(self, api: twitter.UsersApi, flag: ParamType, ct: ClientTransaction):
|
|
26
|
+
def __init__(self, api: twitter.UsersApi, flag: ParamType, ct: Optional[ClientTransaction]):
|
|
27
27
|
self.api = api
|
|
28
28
|
self.flag = flag
|
|
29
29
|
self.ct = ct
|
|
@@ -46,6 +46,7 @@ class UsersApiUtils:
|
|
|
46
46
|
user_ids: list[str],
|
|
47
47
|
extra_param: Optional[ParamType] = None,
|
|
48
48
|
) -> ResponseType:
|
|
49
|
+
"""Deprecated: X answers 403 outside a browser since 2026-10."""
|
|
49
50
|
param: ParamType = {"userIds": user_ids}
|
|
50
51
|
if extra_param is not None:
|
|
51
52
|
param.update(extra_param)
|
twitter_openapi_python/client.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import json
|
|
2
2
|
import re
|
|
3
|
-
from typing import Any
|
|
3
|
+
from typing import Any, Optional
|
|
4
4
|
|
|
5
5
|
import twitter_openapi_python_generated as twitter
|
|
6
6
|
import twitter_openapi_python_generated.configuration as conf
|
|
@@ -29,7 +29,7 @@ class TwitterOpenapiPythonClient:
|
|
|
29
29
|
api: twitter.ApiClient
|
|
30
30
|
placeholder: ParamType
|
|
31
31
|
|
|
32
|
-
def __init__(self, api: twitter.ApiClient, placeholder: ParamType, ct: ClientTransaction):
|
|
32
|
+
def __init__(self, api: twitter.ApiClient, placeholder: ParamType, ct: Optional[ClientTransaction]):
|
|
33
33
|
self.api = api
|
|
34
34
|
self.placeholder = placeholder
|
|
35
35
|
self.ct = ct
|
|
@@ -69,7 +69,7 @@ class TwitterOpenapiPythonClient:
|
|
|
69
69
|
|
|
70
70
|
|
|
71
71
|
class TwitterOpenapiPython:
|
|
72
|
-
hash: str = "
|
|
72
|
+
hash: str = "8535fd9baca301ede55b10da03495a7d413f5102"
|
|
73
73
|
placeholder_url = "https://raw.githubusercontent.com/fa0311/twitter-openapi/{hash}/src/config/placeholder.json"
|
|
74
74
|
header = "https://raw.githubusercontent.com/fa0311/latest-user-agent/refs/heads/main/header.json"
|
|
75
75
|
access_token: str = (
|
|
@@ -137,6 +137,18 @@ class TwitterOpenapiPython:
|
|
|
137
137
|
ct = get_tid()
|
|
138
138
|
return TwitterOpenapiPythonClient(api, json.loads(flag.data), ct)
|
|
139
139
|
|
|
140
|
+
def get_client_from_endpoint(
|
|
141
|
+
self,
|
|
142
|
+
host: str,
|
|
143
|
+
headers: dict[str, str] = {},
|
|
144
|
+
) -> TwitterOpenapiPythonClient:
|
|
145
|
+
http = urllib3.PoolManager()
|
|
146
|
+
flag = http.request("GET", self.placeholder_url.format(hash=self.hash))
|
|
147
|
+
api_client = twitter.ApiClient(configuration=conf.Configuration(host=host))
|
|
148
|
+
for key, value in headers.items():
|
|
149
|
+
api_client.set_default_header(key, value)
|
|
150
|
+
return TwitterOpenapiPythonClient(api_client, json.loads(flag.data), None)
|
|
151
|
+
|
|
140
152
|
def get_client_from_cookies(
|
|
141
153
|
self,
|
|
142
154
|
cookies: dict[str, str],
|
|
@@ -40,7 +40,7 @@ def non_nullable_list(x: List[Optional[T]]) -> List[T]:
|
|
|
40
40
|
return list(filter(filter_fn, x))
|
|
41
41
|
|
|
42
42
|
|
|
43
|
-
def get_kwargs(flag: ParamType, additional: ParamType, ct: ClientTransaction) -> ParamType:
|
|
43
|
+
def get_kwargs(flag: ParamType, additional: ParamType, ct: Optional[ClientTransaction]) -> ParamType:
|
|
44
44
|
assert flag is not None
|
|
45
45
|
kwargs = {"path_query_id": flag["queryId"]}
|
|
46
46
|
if flag.get("variables") is not None:
|
|
@@ -54,7 +54,9 @@ def get_kwargs(flag: ParamType, additional: ParamType, ct: ClientTransaction) ->
|
|
|
54
54
|
return kwargs
|
|
55
55
|
|
|
56
56
|
|
|
57
|
-
def get_headers(flag: ParamType, ct: ClientTransaction) -> Dict[str, str]:
|
|
57
|
+
def get_headers(flag: ParamType, ct: Optional[ClientTransaction]) -> Dict[str, str]:
|
|
58
|
+
if ct is None:
|
|
59
|
+
return {}
|
|
58
60
|
tid = ct.generate_transaction_id(flag["@method"], flag["@path"])
|
|
59
61
|
return {"x-client-transaction-id": tid}
|
|
60
62
|
|
|
@@ -196,7 +198,7 @@ def tweet_results_converter(tweetResults: models.ItemResult) -> Optional[models.
|
|
|
196
198
|
return properties
|
|
197
199
|
elif isinstance(properties, models.TweetWithVisibilityResults):
|
|
198
200
|
return properties.tweet
|
|
199
|
-
elif isinstance(properties, models.TweetTombstone):
|
|
201
|
+
elif isinstance(properties, (models.TweetTombstone, models.TweetUnavailable, models.TweetPreviewDisplay)):
|
|
200
202
|
return None
|
|
201
203
|
raise Exception()
|
|
202
204
|
|
|
@@ -304,7 +306,7 @@ def build_header(headers: Dict[str, str]) -> ApiUtilsHeader:
|
|
|
304
306
|
def timeline_request(
|
|
305
307
|
api_fn: Callable[..., twitter.ApiResponse[T1]],
|
|
306
308
|
flag: ParamType,
|
|
307
|
-
ct: ClientTransaction,
|
|
309
|
+
ct: Optional[ClientTransaction],
|
|
308
310
|
convert_fn: Callable[[T1], List[models.InstructionUnion]],
|
|
309
311
|
param: ParamType,
|
|
310
312
|
items_fn: Callable[[List[models.TimelineAddEntry]], List[T2]],
|
|
@@ -323,7 +325,7 @@ def timeline_request(
|
|
|
323
325
|
def data_request(
|
|
324
326
|
api_fn: Callable[..., twitter.ApiResponse[T1]],
|
|
325
327
|
flag: ParamType,
|
|
326
|
-
ct: ClientTransaction,
|
|
328
|
+
ct: Optional[ClientTransaction],
|
|
327
329
|
convert_fn: Callable[[T1], T2],
|
|
328
330
|
param: ParamType,
|
|
329
331
|
) -> TwitterApiUtilsResponse[T2]:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: twitter_openapi_python
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Twitter OpenAPI
|
|
5
5
|
Keywords: twitter,api,python,scraper
|
|
6
6
|
Author: fa0311
|
|
@@ -8,7 +8,7 @@ Author-email: fa0311 <yuki@yuki0311.com>
|
|
|
8
8
|
License-Expression: LicenseRef-Custom OR AGPL-3.0-or-later
|
|
9
9
|
License-File: LICENSE
|
|
10
10
|
License-File: LICENSE.AGPL
|
|
11
|
-
Requires-Dist: twitter-openapi-python-generated==0.1.
|
|
11
|
+
Requires-Dist: twitter-openapi-python-generated==0.1.4
|
|
12
12
|
Requires-Dist: pydantic>=2.6
|
|
13
13
|
Requires-Dist: requests>=2.31.0,<3.0.0
|
|
14
14
|
Requires-Dist: urllib3>=2.1.0,<3.0.0
|
|
@@ -100,6 +100,17 @@ client.additional_api_headers = {
|
|
|
100
100
|
};
|
|
101
101
|
```
|
|
102
102
|
|
|
103
|
+
### Endpoint
|
|
104
|
+
|
|
105
|
+
The generated client accepts any host that keeps X's path shape (`/graphql/{queryId}/{operationName}`, `/1.1/...`, `/2/...` under `https://x.com/i/api`). `get_client_from_endpoint` is for a host that already holds the session: it sends no cookie, no bearer, no browser headers and no transaction id, only the query and the headers you pass (the second argument is added to every request, for whatever the host defines). For example, [twitter_api_safe_relay](https://github.com/fa0311/twitter_api_safe_relay) answers at `http://localhost:3000/i/api` with a logged-in browser session.
|
|
106
|
+
|
|
107
|
+
```python
|
|
108
|
+
from twitter_openapi_python import TwitterOpenapiPython
|
|
109
|
+
|
|
110
|
+
client = TwitterOpenapiPython().get_client_from_endpoint("http://localhost:3000/i/api")
|
|
111
|
+
response = client.get_user_api().get_user_by_screen_name(screen_name="elonmusk")
|
|
112
|
+
```
|
|
113
|
+
|
|
103
114
|
## Development
|
|
104
115
|
|
|
105
116
|
```shell
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
twitter_openapi_python/__init__.py,sha256=IyCanHNVJtKPGaYEMBqF37VXfMtZNUJlPhSOZMvO5jg,324
|
|
2
2
|
twitter_openapi_python/api/__init__.py,sha256=1YPsr8wnqlrBFAViXCwYwDdk2kNwA6PMC8DAnsWC62U,772
|
|
3
|
-
twitter_openapi_python/api/birdwatch_api.py,sha256=
|
|
4
|
-
twitter_openapi_python/api/community_api.py,sha256=
|
|
5
|
-
twitter_openapi_python/api/default_api.py,sha256=
|
|
3
|
+
twitter_openapi_python/api/birdwatch_api.py,sha256=5Nk1wqpsUmAFQXytpNP5tVAnEUy06r0Yb7oJMA1jbDc,4131
|
|
4
|
+
twitter_openapi_python/api/community_api.py,sha256=AA59UgBz_l2i9ny9rNyPxFUVj5zR40WKQavHr5SLxs0,5389
|
|
5
|
+
twitter_openapi_python/api/default_api.py,sha256=rE6hrAe_wxBkiYe6ZhdseSHMwFuBzSeItDTRqop4J7M,7775
|
|
6
6
|
twitter_openapi_python/api/initial_state_api.py,sha256=nAkb25-btWdMoSyyncxS_VrBQ9uKDgzmG7jBubfETYo,2269
|
|
7
|
-
twitter_openapi_python/api/post_api.py,sha256=
|
|
8
|
-
twitter_openapi_python/api/tweet_api.py,sha256=
|
|
9
|
-
twitter_openapi_python/api/user_api.py,sha256=
|
|
10
|
-
twitter_openapi_python/api/user_list_api.py,sha256=
|
|
11
|
-
twitter_openapi_python/api/users_api.py,sha256=
|
|
7
|
+
twitter_openapi_python/api/post_api.py,sha256=bmVMHcEMrBcwL3nkqf1mqx2Y2TYgFiEIyaUQVcgFoyw,13176
|
|
8
|
+
twitter_openapi_python/api/tweet_api.py,sha256=v9Qf5FOGTDmrT6zuQwlDixYxxkP0LNwZpE-btVSYCoc,24236
|
|
9
|
+
twitter_openapi_python/api/user_api.py,sha256=D9K3OVIZFYhZMTDMFvy42-8kMBE6xisiSMa3yQhIQIo,5259
|
|
10
|
+
twitter_openapi_python/api/user_list_api.py,sha256=8WxhVU69I_mmVlgdvkeIKFw1vcE2raDQ4kBTTMX_ua4,13481
|
|
11
|
+
twitter_openapi_python/api/users_api.py,sha256=VGdJV-vDZ1_4E1lddzHkrRGIdLhuYdOSXLTjjmLudQI,3253
|
|
12
12
|
twitter_openapi_python/api/v11_get_api.py,sha256=UXe34f6IBYExqWCJ8HCld_8d_ChQb92je0G5VtLxmyM,1978
|
|
13
13
|
twitter_openapi_python/api/v11_post_api.py,sha256=eErGBOo-y4E1AAMIHgeWnc0rAFmc5KgIoipJI-8V0Y8,1781
|
|
14
|
-
twitter_openapi_python/client.py,sha256=
|
|
14
|
+
twitter_openapi_python/client.py,sha256=K8qz5O7jwmgxHUjhSm8HOq7kbXsxCj39NKMVWqghpXk,7670
|
|
15
15
|
twitter_openapi_python/models/__init__.py,sha256=pHISZJrEPBlXS25kMydl1SxXuCct-CUpnPDfL7kEEBo,588
|
|
16
16
|
twitter_openapi_python/models/base.py,sha256=3sw6wdQn9i8FoujFxhEFVWIB26-qjI6JTDuXKuebM0Y,189
|
|
17
17
|
twitter_openapi_python/models/header.py,sha256=EKujtBRZOJmeh2SD1QOCsLWaE9gdGY4wsNUgwCnbTCU,644
|
|
@@ -21,9 +21,9 @@ twitter_openapi_python/models/timeline.py,sha256=dRMoc7zqyW_E2iehs4F6HfX8Iy_1b-e
|
|
|
21
21
|
twitter_openapi_python/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
22
22
|
twitter_openapi_python/tid.py,sha256=xjqJMyPOp62nw2MQjMGHaB4L6G6OZHuWkMR-WKJo7aU,1120
|
|
23
23
|
twitter_openapi_python/utils/__init__.py,sha256=lIEPoDqtgCvUk0A8cWqdTlTWMhkEp_NbVxL7sJ0uiu8,612
|
|
24
|
-
twitter_openapi_python/utils/api.py,sha256=
|
|
25
|
-
twitter_openapi_python-0.1.
|
|
26
|
-
twitter_openapi_python-0.1.
|
|
27
|
-
twitter_openapi_python-0.1.
|
|
28
|
-
twitter_openapi_python-0.1.
|
|
29
|
-
twitter_openapi_python-0.1.
|
|
24
|
+
twitter_openapi_python/utils/api.py,sha256=1GCVabc9Reff_-OKWs4c4rAek4uIRCpBRIUMHE7Ht_c,12755
|
|
25
|
+
twitter_openapi_python-0.1.5.dist-info/licenses/LICENSE,sha256=sLv8EMhrPCMG_LeweYvYKS_B-cDMBwBSKZel7LSMGAs,1493
|
|
26
|
+
twitter_openapi_python-0.1.5.dist-info/licenses/LICENSE.AGPL,sha256=TfPDBt3ar0uv_f9cqCDMZ5rIzW3CY8anRRd4PkL6ejs,34522
|
|
27
|
+
twitter_openapi_python-0.1.5.dist-info/WHEEL,sha256=3NO1oYsF7mANFUWVdyEQLM-zmecczWWEmmF5rEbXrWk,80
|
|
28
|
+
twitter_openapi_python-0.1.5.dist-info/METADATA,sha256=u6kZuwIsBBmrD24AFJtA9i3XvUbnSWvmNAzgDR1IoXM,4071
|
|
29
|
+
twitter_openapi_python-0.1.5.dist-info/RECORD,,
|
{twitter_openapi_python-0.1.3.dist-info → twitter_openapi_python-0.1.5.dist-info}/licenses/LICENSE
RENAMED
|
File without changes
|
|
File without changes
|