tweetapi 1.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.
@@ -0,0 +1,32 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional, TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ..client import TweetAPI
7
+ from ..types import (
8
+ ListResponse,
9
+ TweetsPaginatedResponse,
10
+ UserPaginatedResponse,
11
+ )
12
+
13
+
14
+ class ListResource:
15
+ def __init__(self, client: TweetAPI) -> None:
16
+ self._client = client
17
+
18
+ def get_details(self, *, list_id: str) -> ListResponse:
19
+ """Get list details."""
20
+ return self._client._get("/tw-v2/list/details", {"listId": list_id})
21
+
22
+ def get_tweets(self, *, list_id: str, cursor: Optional[str] = None) -> TweetsPaginatedResponse:
23
+ """Get tweets in a list."""
24
+ return self._client._get("/tw-v2/list/tweets", {"listId": list_id, "cursor": cursor})
25
+
26
+ def get_members(self, *, list_id: str, cursor: Optional[str] = None) -> UserPaginatedResponse:
27
+ """Get members of a list."""
28
+ return self._client._get("/tw-v2/list/members", {"listId": list_id, "cursor": cursor})
29
+
30
+ def get_followers(self, *, list_id: str, cursor: Optional[str] = None) -> UserPaginatedResponse:
31
+ """Get followers of a list."""
32
+ return self._client._get("/tw-v2/list/followers", {"listId": list_id, "cursor": cursor})
@@ -0,0 +1,53 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional, TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ..client import TweetAPI
7
+ from ..types import ActionResponse
8
+
9
+
10
+ class PostResource:
11
+ def __init__(self, client: TweetAPI) -> None:
12
+ self._client = client
13
+
14
+ def create_post(self, *, auth_token: str, text: str, proxy: str, disable_link_preview: Optional[bool] = None) -> ActionResponse:
15
+ """Create a new tweet."""
16
+ return self._client._post("/tw-v2/interaction/create-post", {
17
+ "authToken": auth_token, "text": text, "proxy": proxy,
18
+ "disableLinkPreview": disable_link_preview,
19
+ })
20
+
21
+ def create_post_quote(self, *, auth_token: str, text: str, attachment_url: str, proxy: str, disable_link_preview: Optional[bool] = None) -> ActionResponse:
22
+ """Create a quote tweet."""
23
+ return self._client._post("/tw-v2/interaction/create-post-quote", {
24
+ "authToken": auth_token, "text": text, "attachmentUrl": attachment_url,
25
+ "proxy": proxy, "disableLinkPreview": disable_link_preview,
26
+ })
27
+
28
+ def create_post_with_media(self, *, auth_token: str, text: str, media: list[Any], proxy: str, disable_link_preview: Optional[bool] = None) -> ActionResponse:
29
+ """Create a tweet with media attachments."""
30
+ return self._client._post("/tw-v2/interaction/create-post-with-media", {
31
+ "authToken": auth_token, "text": text, "media": media,
32
+ "proxy": proxy, "disableLinkPreview": disable_link_preview,
33
+ })
34
+
35
+ def reply_post(self, *, auth_token: str, text: str, tweet_id: str, proxy: str, disable_link_preview: Optional[bool] = None) -> ActionResponse:
36
+ """Reply to a tweet."""
37
+ return self._client._post("/tw-v2/interaction/reply-post", {
38
+ "authToken": auth_token, "text": text, "tweetId": tweet_id,
39
+ "proxy": proxy, "disableLinkPreview": disable_link_preview,
40
+ })
41
+
42
+ def reply_post_with_media(self, *, auth_token: str, text: str, tweet_id: str, media: list[Any], proxy: str, disable_link_preview: Optional[bool] = None) -> ActionResponse:
43
+ """Reply to a tweet with media attachments."""
44
+ return self._client._post("/tw-v2/interaction/reply-post-with-media", {
45
+ "authToken": auth_token, "text": text, "tweetId": tweet_id,
46
+ "media": media, "proxy": proxy, "disableLinkPreview": disable_link_preview,
47
+ })
48
+
49
+ def delete_post(self, *, auth_token: str, tweet_id: str, proxy: Optional[str] = None) -> ActionResponse:
50
+ """Delete a tweet."""
51
+ return self._client._post("/tw-v2/interaction/delete-post", {
52
+ "authToken": auth_token, "tweetId": tweet_id, "proxy": proxy,
53
+ })
@@ -0,0 +1,20 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ..client import TweetAPI
7
+ from ..types import SpaceResponse, SpaceStreamResponse
8
+
9
+
10
+ class SpaceResource:
11
+ def __init__(self, client: TweetAPI) -> None:
12
+ self._client = client
13
+
14
+ def get_by_id(self, *, space_id: str) -> SpaceResponse:
15
+ """Get Space details by ID."""
16
+ return self._client._get("/tw-v2/space/by-id", {"spaceId": space_id})
17
+
18
+ def get_stream_url(self, *, media_key: str) -> SpaceStreamResponse:
19
+ """Get the HLS stream URL for a Space."""
20
+ return self._client._get("/tw-v2/space/stream-url", {"mediaKey": media_key})
@@ -0,0 +1,37 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional, TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ..client import TweetAPI
7
+ from ..types import (
8
+ TweetResponse,
9
+ TweetsPaginatedResponse,
10
+ TweetTranslationResponse,
11
+ UserPaginatedResponse,
12
+ )
13
+
14
+
15
+ class TweetResource:
16
+ def __init__(self, client: TweetAPI) -> None:
17
+ self._client = client
18
+
19
+ def get_details_and_conversation(self, *, tweet_id: str, cursor: Optional[str] = None, sort_by: Optional[str] = None) -> TweetsPaginatedResponse:
20
+ """Get tweet details and conversation thread."""
21
+ return self._client._get("/tw-v2/tweet/details", {"tweetId": tweet_id, "cursor": cursor, "sortBy": sort_by})
22
+
23
+ def get_details_by_ids(self, *, ids: str) -> dict[str, Any]:
24
+ """Get details for multiple tweets by IDs (comma-separated, max 200)."""
25
+ return self._client._get("/tw-v2/tweet/details-by-ids", {"ids": ids})
26
+
27
+ def get_retweets(self, *, tweet_id: str, cursor: Optional[str] = None) -> UserPaginatedResponse:
28
+ """Get users who retweeted a tweet."""
29
+ return self._client._get("/tw-v2/tweet/retweets", {"tweetId": tweet_id, "cursor": cursor})
30
+
31
+ def get_quotes(self, *, tweet_id: str, cursor: Optional[str] = None) -> TweetsPaginatedResponse:
32
+ """Get quote tweets for a tweet."""
33
+ return self._client._get("/tw-v2/tweet/quotes", {"tweetId": tweet_id, "cursor": cursor})
34
+
35
+ def translate(self, *, tweet_id: str, dst_lang: str) -> TweetTranslationResponse:
36
+ """Translate a tweet to a different language."""
37
+ return self._client._post("/tw-v2/tweet/translate", {"tweetId": tweet_id, "dstLang": dst_lang})
@@ -0,0 +1,64 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional, TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ..client import TweetAPI
7
+ from ..types import ActionResponse, ApiResponse, PaginatedResponse
8
+
9
+
10
+ class UnencryptedDMResource:
11
+ def __init__(self, client: TweetAPI) -> None:
12
+ self._client = client
13
+
14
+ def send_dm(self, *, auth_token: str, conversation_id: str, text: str, proxy: str, request_id: Optional[str] = None, media: Optional[list[Any]] = None) -> ActionResponse:
15
+ """Send an unencrypted direct message."""
16
+ return self._client._post("/tw-v2/interaction/send-dm", {
17
+ "authToken": auth_token, "conversationId": conversation_id,
18
+ "text": text, "proxy": proxy, "requestId": request_id, "media": media,
19
+ })
20
+
21
+ def get_dm_permissions(self, *, auth_token: str, recipient_ids: str, proxy: Optional[str] = None) -> ApiResponse:
22
+ """Check DM permissions for recipients."""
23
+ return self._client._get("/tw-v2/interaction/dm-permissions", {
24
+ "authToken": auth_token, "recipientIds": recipient_ids, "proxy": proxy,
25
+ })
26
+
27
+ def get_inbox_initial_state(self, *, auth_token: str, proxy: Optional[str] = None) -> ApiResponse:
28
+ """Get initial inbox state."""
29
+ return self._client._get("/tw-v2/interaction/inbox-initial-state", {
30
+ "authToken": auth_token, "proxy": proxy,
31
+ })
32
+
33
+ def get_inbox_trusted(self, *, auth_token: str, cursor: str, filter_low_quality: Optional[bool] = None, proxy: Optional[str] = None) -> PaginatedResponse:
34
+ """Get trusted inbox conversations."""
35
+ return self._client._get("/tw-v2/interaction/inbox-timeline-trusted", {
36
+ "authToken": auth_token, "cursor": cursor,
37
+ "filterLowQuality": filter_low_quality, "proxy": proxy,
38
+ })
39
+
40
+ def get_inbox_untrusted(self, *, auth_token: str, cursor: str, filter_low_quality: Optional[bool] = None, proxy: Optional[str] = None) -> PaginatedResponse:
41
+ """Get untrusted (message requests) inbox conversations."""
42
+ return self._client._get("/tw-v2/interaction/inbox-timeline-untrusted", {
43
+ "authToken": auth_token, "cursor": cursor,
44
+ "filterLowQuality": filter_low_quality, "proxy": proxy,
45
+ })
46
+
47
+ def get_conversation(self, *, auth_token: str, conversation_id: str, cursor: Optional[str] = None, proxy: Optional[str] = None) -> PaginatedResponse:
48
+ """Get messages in a conversation."""
49
+ return self._client._get("/tw-v2/interaction/conversation", {
50
+ "authToken": auth_token, "conversationId": conversation_id,
51
+ "cursor": cursor, "proxy": proxy,
52
+ })
53
+
54
+ def get_dm_user_updates(self, *, auth_token: str, cursor: str, proxy: Optional[str] = None) -> PaginatedResponse:
55
+ """Get DM user updates."""
56
+ return self._client._get("/tw-v2/interaction/dm-user-updates", {
57
+ "authToken": auth_token, "cursor": cursor, "proxy": proxy,
58
+ })
59
+
60
+ def accept_conversation(self, *, auth_token: str, conversation_id: str, proxy: Optional[str] = None) -> ActionResponse:
61
+ """Accept a conversation request."""
62
+ return self._client._post("/tw-v2/interaction/accept-conversation", {
63
+ "authToken": auth_token, "conversationId": conversation_id, "proxy": proxy,
64
+ })
@@ -0,0 +1,84 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional, TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ..client import TweetAPI
7
+ from ..types import (
8
+ UserResponse,
9
+ UsersResponse,
10
+ UserPaginatedResponse,
11
+ UserRelationshipResponse,
12
+ TweetsPaginatedResponse,
13
+ PaginatedResponse,
14
+ ApiResponse,
15
+ )
16
+
17
+
18
+ class UserResource:
19
+ def __init__(self, client: TweetAPI) -> None:
20
+ self._client = client
21
+
22
+ def get_by_username(self, *, username: str) -> UserResponse:
23
+ """Get a user profile by username."""
24
+ return self._client._get("/tw-v2/user/by-username", {"username": username})
25
+
26
+ def get_by_usernames(self, *, usernames: str) -> UsersResponse:
27
+ """Get multiple user profiles by usernames (comma-separated)."""
28
+ return self._client._get("/tw-v2/user/by-usernames", {"usernames": usernames})
29
+
30
+ def get_by_user_id(self, *, user_id: str) -> UserResponse:
31
+ """Get a user profile by user ID."""
32
+ return self._client._get("/tw-v2/user/by-id", {"userId": user_id})
33
+
34
+ def get_by_user_ids(self, *, user_ids: list[str]) -> UsersResponse:
35
+ """Get multiple user profiles by user IDs (list of ID strings, max 50)."""
36
+ return self._client._get("/tw-v2/user/by-ids", {"userIds": user_ids})
37
+
38
+ def get_tweets(self, *, user_id: str, cursor: Optional[str] = None) -> TweetsPaginatedResponse:
39
+ """Get a user's tweets."""
40
+ return self._client._get("/tw-v2/user/tweets", {"userId": user_id, "cursor": cursor})
41
+
42
+ def get_tweets_and_replies(self, *, user_id: str, cursor: Optional[str] = None) -> TweetsPaginatedResponse:
43
+ """Get a user's tweets and replies."""
44
+ return self._client._get("/tw-v2/user/tweets-and-replies", {"userId": user_id, "cursor": cursor})
45
+
46
+ def get_following(self, *, user_id: str, cursor: Optional[str] = None) -> UserPaginatedResponse:
47
+ """Get who a user follows (v2 — full user objects)."""
48
+ return self._client._get("/tw-v2/user/following", {"userId": user_id, "cursor": cursor})
49
+
50
+ def get_followers(self, *, user_id: str, cursor: Optional[str] = None) -> UserPaginatedResponse:
51
+ """Get a user's followers (v2 — full user objects)."""
52
+ return self._client._get("/tw-v2/user/followers", {"userId": user_id, "cursor": cursor})
53
+
54
+ def get_verified_followers(self, *, user_id: str, cursor: Optional[str] = None) -> UserPaginatedResponse:
55
+ """Get a user's verified followers."""
56
+ return self._client._get("/tw-v2/user/verified-followers", {"userId": user_id, "cursor": cursor})
57
+
58
+ def get_subscriptions(self, *, user_id: str, cursor: Optional[str] = None) -> UserPaginatedResponse:
59
+ """Get a user's subscriptions."""
60
+ return self._client._get("/tw-v2/user/subscriptions", {"userId": user_id, "cursor": cursor})
61
+
62
+ def get_following_v1(self, *, user_id: str, count: Optional[str] = None, cursor: Optional[str] = None) -> UserPaginatedResponse:
63
+ """Get who a user follows (v1 — supports count)."""
64
+ return self._client._get("/tw-v2/user/following-list", {"userId": user_id, "count": count, "cursor": cursor})
65
+
66
+ def get_followers_v1(self, *, user_id: str, count: Optional[str] = None, cursor: Optional[str] = None) -> UserPaginatedResponse:
67
+ """Get a user's followers (v1 — supports count)."""
68
+ return self._client._get("/tw-v2/user/followers-list", {"userId": user_id, "count": count, "cursor": cursor})
69
+
70
+ def get_following_ids(self, *, user_id: str, count: Optional[str] = None, cursor: Optional[str] = None) -> PaginatedResponse:
71
+ """Get IDs of accounts a user is following."""
72
+ return self._client._get("/tw-v2/user/following-ids", {"userId": user_id, "count": count, "cursor": cursor})
73
+
74
+ def get_followers_ids(self, *, user_id: str, count: Optional[str] = None, cursor: Optional[str] = None) -> PaginatedResponse:
75
+ """Get IDs of a user's followers."""
76
+ return self._client._get("/tw-v2/user/followers-ids", {"userId": user_id, "count": count, "cursor": cursor})
77
+
78
+ def check_follow(self, *, subject_id: str, target_id: str) -> UserRelationshipResponse:
79
+ """Check the follow relationship between two users."""
80
+ return self._client._get("/tw-v2/user/friendship", {"subjectId": subject_id, "targetId": target_id})
81
+
82
+ def about_account(self, *, username: str) -> ApiResponse:
83
+ """Get account creation details and transparency information."""
84
+ return self._client._get("/tw-v2/user/about-account", {"username": username})
@@ -0,0 +1,45 @@
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional, TYPE_CHECKING
4
+
5
+ if TYPE_CHECKING:
6
+ from ..client import TweetAPI
7
+ from ..types import ActionResponse, ApiResponse, PaginatedResponse
8
+
9
+
10
+ class XChatResource:
11
+ def __init__(self, client: TweetAPI) -> None:
12
+ self._client = client
13
+
14
+ def setup(self, *, auth_token: str, user_id: str, pin: str, proxy: Optional[str] = None) -> ActionResponse:
15
+ """Initialize X Chat (encrypted DMs) for your account."""
16
+ return self._client._post("/tw-v2/xchat/setup", {
17
+ "authToken": auth_token, "userId": user_id, "pin": pin, "proxy": proxy,
18
+ })
19
+
20
+ def get_conversations(self, *, auth_token: str, cursor: Optional[str] = None, graph_snapshot_id: Optional[str] = None, limit: Optional[int] = None, proxy: Optional[str] = None) -> PaginatedResponse:
21
+ """List encrypted DM conversations."""
22
+ return self._client._post("/tw-v2/xchat/conversations", {
23
+ "authToken": auth_token, "cursor": cursor,
24
+ "graphSnapshotId": graph_snapshot_id, "limit": limit, "proxy": proxy,
25
+ })
26
+
27
+ def send(self, *, auth_token: str, recipient_id: str, message: str, proxy: Optional[str] = None) -> ActionResponse:
28
+ """Send an encrypted message."""
29
+ return self._client._post("/tw-v2/xchat/send", {
30
+ "authToken": auth_token, "recipientId": recipient_id,
31
+ "message": message, "proxy": proxy,
32
+ })
33
+
34
+ def get_history(self, *, auth_token: str, conversation_id: str, cursor: Optional[str] = None, limit: Optional[int] = None, proxy: Optional[str] = None) -> PaginatedResponse:
35
+ """Get encrypted conversation history."""
36
+ return self._client._post("/tw-v2/xchat/history", {
37
+ "authToken": auth_token, "conversationId": conversation_id,
38
+ "cursor": cursor, "limit": limit, "proxy": proxy,
39
+ })
40
+
41
+ def can_dm(self, *, auth_token: str, user_ids: list[str], proxy: Optional[str] = None) -> ApiResponse:
42
+ """Check if you can send encrypted DMs to users."""
43
+ return self._client._post("/tw-v2/xchat/can-dm", {
44
+ "authToken": auth_token, "userIds": user_ids, "proxy": proxy,
45
+ })