twitter-openapi-python 0.1.4__tar.gz → 0.1.6__tar.gz

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 (30) hide show
  1. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/PKG-INFO +4 -6
  2. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/README.md +2 -4
  3. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/pyproject.toml +2 -2
  4. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/pyproject.toml.orig +2 -2
  5. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/birdwatch_api.py +1 -1
  6. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/community_api.py +1 -1
  7. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/default_api.py +1 -1
  8. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/post_api.py +1 -1
  9. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/tweet_api.py +1 -1
  10. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/user_api.py +1 -1
  11. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/user_list_api.py +1 -1
  12. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/users_api.py +1 -1
  13. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/client.py +15 -3
  14. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/utils/api.py +6 -4
  15. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/LICENSE +0 -0
  16. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/LICENSE.AGPL +0 -0
  17. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/__init__.py +0 -0
  18. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/__init__.py +0 -0
  19. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/initial_state_api.py +0 -0
  20. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/v11_get_api.py +0 -0
  21. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/api/v11_post_api.py +0 -0
  22. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/models/__init__.py +0 -0
  23. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/models/base.py +0 -0
  24. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/models/header.py +0 -0
  25. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/models/initial_state.py +0 -0
  26. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/models/response.py +0 -0
  27. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/models/timeline.py +0 -0
  28. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/py.typed +0 -0
  29. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/tid.py +0 -0
  30. {twitter_openapi_python-0.1.4 → twitter_openapi_python-0.1.6}/twitter_openapi_python/utils/__init__.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: twitter_openapi_python
3
- Version: 0.1.4
3
+ Version: 0.1.6
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.4
11
+ Requires-Dist: twitter-openapi-python-generated==0.1.5
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
@@ -102,14 +102,12 @@ client.additional_api_headers = {
102
102
 
103
103
  ### Endpoint
104
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`). Build the `ApiClient` yourself and hand it to `get_twitter_openapi_python_client`; the login helpers are not involved, so cookies and headers are then up to you (or to whatever answers at that host). 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.
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
106
 
107
107
  ```python
108
- import twitter_openapi_python_generated as twitter
109
108
  from twitter_openapi_python import TwitterOpenapiPython
110
109
 
111
- api_client = twitter.ApiClient(twitter.Configuration(host="http://localhost:3000/i/api"))
112
- client = TwitterOpenapiPython().get_twitter_openapi_python_client(api_client)
110
+ client = TwitterOpenapiPython().get_client_from_endpoint("http://localhost:3000/i/api")
113
111
  response = client.get_user_api().get_user_by_screen_name(screen_name="elonmusk")
114
112
  ```
115
113
 
@@ -83,14 +83,12 @@ client.additional_api_headers = {
83
83
 
84
84
  ### Endpoint
85
85
 
86
- The generated client accepts any host that keeps X's path shape (`/graphql/{queryId}/{operationName}`, `/1.1/...`, `/2/...` under `https://x.com/i/api`). Build the `ApiClient` yourself and hand it to `get_twitter_openapi_python_client`; the login helpers are not involved, so cookies and headers are then up to you (or to whatever answers at that host). 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.
86
+ 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.
87
87
 
88
88
  ```python
89
- import twitter_openapi_python_generated as twitter
90
89
  from twitter_openapi_python import TwitterOpenapiPython
91
90
 
92
- api_client = twitter.ApiClient(twitter.Configuration(host="http://localhost:3000/i/api"))
93
- client = TwitterOpenapiPython().get_twitter_openapi_python_client(api_client)
91
+ client = TwitterOpenapiPython().get_client_from_endpoint("http://localhost:3000/i/api")
94
92
  response = client.get_user_api().get_user_by_screen_name(screen_name="elonmusk")
95
93
  ```
96
94
 
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twitter_openapi_python"
3
- version = "0.1.4"
3
+ version = "0.1.6"
4
4
  description = "Twitter OpenAPI"
5
5
  readme = "README.md"
6
6
  license = "LicenseRef-Custom OR AGPL-3.0-or-later"
@@ -16,7 +16,7 @@ keywords = [
16
16
  ]
17
17
  requires-python = ">=3.10"
18
18
  dependencies = [
19
- "twitter_openapi_python_generated==0.1.4",
19
+ "twitter_openapi_python_generated==0.1.5",
20
20
  "pydantic>=2.6",
21
21
  "requests>=2.31.0,<3.0.0",
22
22
  "urllib3>=2.1.0,<3.0.0",
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "twitter_openapi_python"
3
- version = "0.1.4"
3
+ version = "0.1.6"
4
4
  description = "Twitter OpenAPI"
5
5
  authors = [{ name = "fa0311", email = "yuki@yuki0311.com" }]
6
6
  readme = "README.md"
@@ -9,7 +9,7 @@ license-files = ["LICENSE", "LICENSE.AGPL"]
9
9
  keywords = ["twitter", "api", "python", "scraper"]
10
10
  requires-python = ">=3.10"
11
11
  dependencies = [
12
- "twitter_openapi_python_generated==0.1.4",
12
+ "twitter_openapi_python_generated==0.1.5",
13
13
  "pydantic>=2.6",
14
14
  "requests>=2.31.0,<3.0.0",
15
15
  "urllib3>=2.1.0,<3.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
@@ -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
@@ -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 = "8535fd9baca301ede55b10da03495a7d413f5102"
72
+ hash: str = "975196678177a65210cff715a1b93ddfc83584eb"
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
 
@@ -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]: