kickpython 0.1.0__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.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 berkay.digital
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,9 @@
1
+ include LICENSE
2
+ include README.md
3
+ include requirements.txt
4
+ recursive-include docs *.md
5
+ recursive-include kickpy *.py *.pyi py.typed
6
+ recursive-include tests *.py
7
+ global-exclude __pycache__
8
+ global-exclude *.py[cod]
9
+ global-exclude *.db
@@ -0,0 +1,196 @@
1
+ Metadata-Version: 2.2
2
+ Name: kickpython
3
+ Version: 0.1.0
4
+ Summary: Python wrapper for Kick.com API
5
+ Home-page: https://github.com/berkay-digital/kickpython
6
+ Author: berkay.digital
7
+ Author-email: "berkay.digital" <contact@berkay.digital>
8
+ License: MIT
9
+ Project-URL: Homepage, https://github.com/berkay-digital/kickpython
10
+ Project-URL: Documentation, https://github.com/berkay-digital/kickpython/tree/main/docs
11
+ Project-URL: Repository, https://github.com/berkay-digital/kickpython.git
12
+ Project-URL: Issues, https://github.com/berkay-digital/kickpython/issues
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Dynamic: author
17
+ Dynamic: home-page
18
+ Dynamic: requires-python
19
+
20
+ # KickPython - Python API Wrapper
21
+
22
+ A Python wrapper for the Kick.com API that provides easy access to Kick.com's public API endpoints and WebSocket chat functionality.
23
+
24
+ ## Installation
25
+
26
+ ```bash
27
+ pip install kickpython
28
+ ```
29
+
30
+ ## Features
31
+
32
+ - OAuth 2.1 authentication with PKCE support
33
+ - Automatic token storage and refresh
34
+ - Channel management
35
+ - Chat message sending and receiving
36
+ - WebSocket-based chat listener
37
+ - Support for channel category management
38
+ - Proxy support
39
+
40
+ ## Usage
41
+
42
+ ### Basic Initialization
43
+
44
+ ```python
45
+ from kickpython import KickAPI
46
+
47
+ # For OAuth 2.1 authentication (recommended)
48
+ api = KickAPI(
49
+ client_id="your_client_id",
50
+ client_secret="your_client_secret",
51
+ redirect_uri="your_redirect_uri",
52
+ db_path="kick_tokens.db" # Optional, defaults to kick_tokens.db
53
+ )
54
+
55
+ # With proxy support
56
+ api = KickAPI(
57
+ client_id="your_client_id",
58
+ client_secret="your_client_secret",
59
+ redirect_uri="your_redirect_uri",
60
+ proxy="proxy.example.com:8080",
61
+ proxy_auth="username:password"
62
+ )
63
+ ```
64
+
65
+ ### OAuth Authentication
66
+
67
+ ```python
68
+ # Generate authorization URL with PKCE
69
+ auth_data = api.get_auth_url([
70
+ "user:read",
71
+ "channel:read",
72
+ "channel:write",
73
+ "chat:write",
74
+ "events:subscribe"
75
+ ])
76
+
77
+ # The auth URL for user authorization
78
+ auth_url = auth_data["auth_url"]
79
+ code_verifier = auth_data["code_verifier"]
80
+ state = auth_data["state"]
81
+
82
+ # After user authorization, exchange the code for tokens
83
+ token_data = await api.exchange_code(code, code_verifier)
84
+
85
+ # Tokens are automatically stored and managed
86
+ await api.start_token_refresh() # Start automatic token refresh
87
+ ```
88
+
89
+ ### Chat Functionality
90
+
91
+ #### Sending Messages
92
+
93
+ ```python
94
+ # Send a chat message
95
+ await api.post_chat(
96
+ channel_id="123",
97
+ content="Hello from the bot!"
98
+ )
99
+ ```
100
+
101
+ #### Listening to Chat Messages
102
+
103
+ ```python
104
+ # Define a message handler
105
+ async def message_handler(message):
106
+ username = message['sender_username']
107
+ content = message['content']
108
+ badges = message['badges']
109
+ chat_id = message['chat_id']
110
+ print(f"{username}: {content}")
111
+
112
+ # Add the message handler
113
+ api.add_message_handler(message_handler)
114
+
115
+ # Connect to a channel's chat
116
+ await api.connect_to_chatroom("channel_username")
117
+ # Or connect using chatroom ID
118
+ await api.connect_to_chatroom("123456")
119
+ ```
120
+
121
+ ### Channel Management
122
+
123
+ ```python
124
+ # Get channel information
125
+ channels = await api.get_channels()
126
+
127
+ # Update channel information
128
+ await api.update_channel(
129
+ channel_id="123",
130
+ category_id="456",
131
+ stream_title="New Stream Title"
132
+ )
133
+ ```
134
+
135
+ ### Category Management
136
+
137
+ ```python
138
+ # Get list of categories
139
+ categories = await api.get_categories()
140
+
141
+ # Search for specific categories
142
+ results = await api.get_categories(query="games")
143
+
144
+ # Get specific category
145
+ category = await api.get_category(category_id="123")
146
+ ```
147
+
148
+ ## Complete Examples
149
+
150
+ ### OAuth Web Server
151
+
152
+ See [examples/oauth.py](kickpython/examples/oauth.py) for a complete Flask-based OAuth implementation that includes:
153
+ - OAuth authorization flow with PKCE
154
+ - Token management interface
155
+ - Token refresh and revocation
156
+ - Example API usage
157
+
158
+ ### Chat Bot
159
+
160
+ See [examples/listen_all_channels.py](kickpython/examples/listen_all_channels.py) for a chat bot example that:
161
+ - Connects to multiple channels
162
+ - Handles chat messages
163
+ - Responds to commands
164
+ - Handles reconnection
165
+
166
+ ## Error Handling
167
+
168
+ The API methods throw exceptions for error conditions:
169
+ - `ValueError` for invalid input parameters
170
+ - `Exception` for API errors with error messages
171
+
172
+ Example:
173
+ ```python
174
+ try:
175
+ await api.post_chat(channel_id="123", content="")
176
+ except ValueError as e:
177
+ print("Invalid parameters:", e)
178
+ except Exception as e:
179
+ print("API error:", e)
180
+ ```
181
+
182
+ ## Available Scopes
183
+
184
+ - `user:read` - Access user information
185
+ - `channel:read` - Access channel information
186
+ - `channel:write` - Update channel metadata
187
+ - `chat:write` - Send chat messages
188
+ - `events:subscribe` - Subscribe to channel events
189
+
190
+ ## Contributing
191
+
192
+ Contributions are welcome! Please feel free to submit a Pull Request.
193
+
194
+ ## License
195
+
196
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,177 @@
1
+ # KickPython - Python API Wrapper
2
+
3
+ A Python wrapper for the Kick.com API that provides easy access to Kick.com's public API endpoints and WebSocket chat functionality.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ pip install kickpython
9
+ ```
10
+
11
+ ## Features
12
+
13
+ - OAuth 2.1 authentication with PKCE support
14
+ - Automatic token storage and refresh
15
+ - Channel management
16
+ - Chat message sending and receiving
17
+ - WebSocket-based chat listener
18
+ - Support for channel category management
19
+ - Proxy support
20
+
21
+ ## Usage
22
+
23
+ ### Basic Initialization
24
+
25
+ ```python
26
+ from kickpython import KickAPI
27
+
28
+ # For OAuth 2.1 authentication (recommended)
29
+ api = KickAPI(
30
+ client_id="your_client_id",
31
+ client_secret="your_client_secret",
32
+ redirect_uri="your_redirect_uri",
33
+ db_path="kick_tokens.db" # Optional, defaults to kick_tokens.db
34
+ )
35
+
36
+ # With proxy support
37
+ api = KickAPI(
38
+ client_id="your_client_id",
39
+ client_secret="your_client_secret",
40
+ redirect_uri="your_redirect_uri",
41
+ proxy="proxy.example.com:8080",
42
+ proxy_auth="username:password"
43
+ )
44
+ ```
45
+
46
+ ### OAuth Authentication
47
+
48
+ ```python
49
+ # Generate authorization URL with PKCE
50
+ auth_data = api.get_auth_url([
51
+ "user:read",
52
+ "channel:read",
53
+ "channel:write",
54
+ "chat:write",
55
+ "events:subscribe"
56
+ ])
57
+
58
+ # The auth URL for user authorization
59
+ auth_url = auth_data["auth_url"]
60
+ code_verifier = auth_data["code_verifier"]
61
+ state = auth_data["state"]
62
+
63
+ # After user authorization, exchange the code for tokens
64
+ token_data = await api.exchange_code(code, code_verifier)
65
+
66
+ # Tokens are automatically stored and managed
67
+ await api.start_token_refresh() # Start automatic token refresh
68
+ ```
69
+
70
+ ### Chat Functionality
71
+
72
+ #### Sending Messages
73
+
74
+ ```python
75
+ # Send a chat message
76
+ await api.post_chat(
77
+ channel_id="123",
78
+ content="Hello from the bot!"
79
+ )
80
+ ```
81
+
82
+ #### Listening to Chat Messages
83
+
84
+ ```python
85
+ # Define a message handler
86
+ async def message_handler(message):
87
+ username = message['sender_username']
88
+ content = message['content']
89
+ badges = message['badges']
90
+ chat_id = message['chat_id']
91
+ print(f"{username}: {content}")
92
+
93
+ # Add the message handler
94
+ api.add_message_handler(message_handler)
95
+
96
+ # Connect to a channel's chat
97
+ await api.connect_to_chatroom("channel_username")
98
+ # Or connect using chatroom ID
99
+ await api.connect_to_chatroom("123456")
100
+ ```
101
+
102
+ ### Channel Management
103
+
104
+ ```python
105
+ # Get channel information
106
+ channels = await api.get_channels()
107
+
108
+ # Update channel information
109
+ await api.update_channel(
110
+ channel_id="123",
111
+ category_id="456",
112
+ stream_title="New Stream Title"
113
+ )
114
+ ```
115
+
116
+ ### Category Management
117
+
118
+ ```python
119
+ # Get list of categories
120
+ categories = await api.get_categories()
121
+
122
+ # Search for specific categories
123
+ results = await api.get_categories(query="games")
124
+
125
+ # Get specific category
126
+ category = await api.get_category(category_id="123")
127
+ ```
128
+
129
+ ## Complete Examples
130
+
131
+ ### OAuth Web Server
132
+
133
+ See [examples/oauth.py](kickpython/examples/oauth.py) for a complete Flask-based OAuth implementation that includes:
134
+ - OAuth authorization flow with PKCE
135
+ - Token management interface
136
+ - Token refresh and revocation
137
+ - Example API usage
138
+
139
+ ### Chat Bot
140
+
141
+ See [examples/listen_all_channels.py](kickpython/examples/listen_all_channels.py) for a chat bot example that:
142
+ - Connects to multiple channels
143
+ - Handles chat messages
144
+ - Responds to commands
145
+ - Handles reconnection
146
+
147
+ ## Error Handling
148
+
149
+ The API methods throw exceptions for error conditions:
150
+ - `ValueError` for invalid input parameters
151
+ - `Exception` for API errors with error messages
152
+
153
+ Example:
154
+ ```python
155
+ try:
156
+ await api.post_chat(channel_id="123", content="")
157
+ except ValueError as e:
158
+ print("Invalid parameters:", e)
159
+ except Exception as e:
160
+ print("API error:", e)
161
+ ```
162
+
163
+ ## Available Scopes
164
+
165
+ - `user:read` - Access user information
166
+ - `channel:read` - Access channel information
167
+ - `channel:write` - Update channel metadata
168
+ - `chat:write` - Send chat messages
169
+ - `events:subscribe` - Subscribe to channel events
170
+
171
+ ## Contributing
172
+
173
+ Contributions are welcome! Please feel free to submit a Pull Request.
174
+
175
+ ## License
176
+
177
+ This project is licensed under the MIT License - see the LICENSE file for details.
@@ -0,0 +1,102 @@
1
+ # Authentication
2
+
3
+ This document covers the OAuth 2.1 authentication functionality in the Kick Python API wrapper.
4
+
5
+ ## OAuth 2.1 Flow
6
+
7
+ The API uses OAuth 2.1 with PKCE (Proof Key for Code Exchange) for secure authentication.
8
+
9
+ ### Initialization
10
+
11
+ ```python
12
+ from kickpy import KickAPI
13
+
14
+ api = KickAPI(
15
+ client_id="your_client_id",
16
+ client_secret="your_client_secret",
17
+ redirect_uri="your_redirect_uri"
18
+ )
19
+ ```
20
+
21
+ ### Generate Authorization URL
22
+
23
+ ```python
24
+ auth_data = api.get_auth_url([
25
+ "user:read",
26
+ "channel:read",
27
+ "channel:write",
28
+ "chat:write",
29
+ "events:subscribe"
30
+ ])
31
+
32
+ auth_url = auth_data["auth_url"] # URL to redirect user to
33
+ code_verifier = auth_data["code_verifier"] # Store this for token exchange
34
+ state = auth_data["state"] # CSRF protection token
35
+ ```
36
+
37
+ ### Exchange Code for Tokens
38
+
39
+ After the user authorizes your application, exchange the code for tokens:
40
+
41
+ ```python
42
+ token_data = await api.exchange_code(
43
+ code="auth_code_from_redirect",
44
+ code_verifier=code_verifier,
45
+ channel_id="optional_channel_id" # If not provided, will be fetched from token
46
+ )
47
+ ```
48
+
49
+ The tokens are automatically stored in the SQLite database specified during initialization.
50
+
51
+ ### Token Management
52
+
53
+ #### Automatic Token Refresh
54
+ ```python
55
+ # Start automatic token refresh (refreshes hourly)
56
+ await api.start_token_refresh()
57
+
58
+ # Stop automatic token refresh
59
+ await api.stop_token_refresh()
60
+ ```
61
+
62
+ #### Manual Token Operations
63
+ ```python
64
+ # Manually refresh a token
65
+ new_token_data = await api.refresh_token(
66
+ channel_id="123",
67
+ refresh_token="optional_refresh_token" # If not provided, fetched from DB
68
+ )
69
+
70
+ # Revoke a token
71
+ success = await api.revoke_token(
72
+ channel_id="123",
73
+ token_type="access_token" # or "refresh_token"
74
+ )
75
+
76
+ # Check if token exists
77
+ has_token = api.check_token_exists("channel_id")
78
+ ```
79
+
80
+ ## Available Scopes
81
+
82
+ - `user:read` - Access user information
83
+ - `channel:read` - Access channel information
84
+ - `channel:write` - Update channel metadata
85
+ - `chat:write` - Send chat messages
86
+ - `events:subscribe` - Subscribe to channel events
87
+
88
+ ## Error Handling
89
+
90
+ Authentication methods may throw:
91
+ - `ValueError` if required parameters are missing
92
+ - `Exception` with error details from the API
93
+
94
+ Example:
95
+ ```python
96
+ try:
97
+ await api.exchange_code(code="invalid_code", code_verifier="verifier")
98
+ except ValueError as e:
99
+ print("Missing parameters:", e)
100
+ except Exception as e:
101
+ print("Auth error:", e)
102
+ ```
@@ -0,0 +1,97 @@
1
+ # Channel Management
2
+
3
+ This document covers the channel management functionality in the Kick Python API wrapper.
4
+
5
+ ## Channel Information
6
+
7
+ ### Get Channels
8
+
9
+ Retrieve information about channels:
10
+
11
+ ```python
12
+ # Get all channels
13
+ channels = await api.get_channels()
14
+
15
+ # Get specific channel
16
+ channels = await api.get_channels(channel_id="123")
17
+ ```
18
+
19
+ ### Update Channel
20
+
21
+ Update a channel's metadata:
22
+
23
+ ```python
24
+ await api.update_channel(
25
+ channel_id="123",
26
+ category_id="456", # New category ID
27
+ stream_title="New Title" # New stream title
28
+ )
29
+ ```
30
+
31
+ ## User Information
32
+
33
+ ### Get Users
34
+
35
+ Retrieve user information:
36
+
37
+ ```python
38
+ # Get all users
39
+ users = await api.get_users()
40
+
41
+ # Get users for specific channel
42
+ users = await api.get_users(channel_id="123")
43
+ ```
44
+
45
+ ### Get Broadcaster ID
46
+
47
+ Get the broadcaster ID from an access token:
48
+
49
+ ```python
50
+ broadcaster_id = await api.get_broadcaster_id(access_token)
51
+ ```
52
+
53
+ ### Fetch Channel Username
54
+
55
+ Get a channel's username from its ID:
56
+
57
+ ```python
58
+ username = await api.fetch_channel_username("channel_id")
59
+ ```
60
+
61
+ ## Categories
62
+
63
+ ### Get All Categories
64
+
65
+ ```python
66
+ # Get all categories
67
+ categories = await api.get_categories()
68
+
69
+ # Search categories
70
+ results = await api.get_categories(query="gaming")
71
+ ```
72
+
73
+ ### Get Specific Category
74
+
75
+ ```python
76
+ category = await api.get_category(category_id="123")
77
+ ```
78
+
79
+ ## Error Handling
80
+
81
+ Channel methods may throw:
82
+ - `ValueError` for invalid inputs
83
+ - `Exception` for API errors
84
+
85
+ Example:
86
+ ```python
87
+ try:
88
+ await api.update_channel(
89
+ channel_id="123",
90
+ category_id="invalid",
91
+ stream_title=""
92
+ )
93
+ except ValueError as e:
94
+ print("Invalid parameters:", e)
95
+ except Exception as e:
96
+ print("API error:", e)
97
+ ```
@@ -0,0 +1,106 @@
1
+ # Chat API
2
+
3
+ This document covers the chat functionality in the Kick Python API wrapper.
4
+
5
+ ## Chat Message Management
6
+
7
+ ### Sending Messages
8
+
9
+ Send messages to a channel's chat:
10
+
11
+ ```python
12
+ await api.post_chat(
13
+ channel_id="123",
14
+ content="Hello from the bot!"
15
+ )
16
+ ```
17
+
18
+ ### Listening to Chat Messages
19
+
20
+ Set up a WebSocket connection to receive chat messages in real-time.
21
+
22
+ #### Basic Chat Connection
23
+
24
+ ```python
25
+ # Connect using username
26
+ await api.connect_to_chatroom("channel_username")
27
+
28
+ # Or connect using chatroom ID
29
+ await api.connect_to_chatroom("123456")
30
+ ```
31
+
32
+ #### Message Handler
33
+
34
+ ```python
35
+ # Define a message handler function
36
+ async def message_handler(message):
37
+ print(f"Username: {message['sender_username']}")
38
+ print(f"Message: {message['content']}")
39
+ print(f"Badges: {message['badges']}")
40
+ print(f"Chat ID: {message['chat_id']}")
41
+ print(f"Timestamp: {message['created_at']}")
42
+
43
+ # Add the handler to receive messages
44
+ api.add_message_handler(message_handler)
45
+ ```
46
+
47
+ #### Continuous Chat Listener
48
+
49
+ ```python
50
+ # Run a continuous chat listener with auto-reconnect
51
+ api.run_chat_listener("channel_username")
52
+ ```
53
+
54
+ ### Chatroom Management
55
+
56
+ #### Get Chatroom ID
57
+
58
+ ```python
59
+ # Get chatroom ID from username
60
+ chatroom_id, user_data = await api.get_chatroom_id("username")
61
+
62
+ # Get channel ID from chatroom ID
63
+ channel_id = api.get_channel_id_from_chatroom("chatroom_id")
64
+ ```
65
+
66
+ #### Monitor Multiple Channels
67
+
68
+ ```python
69
+ # Get all available chatroom IDs
70
+ channels = await api.get_all_chatroom_ids()
71
+ # Returns list of dicts with:
72
+ # - username
73
+ # - chatroom_id
74
+ ```
75
+
76
+ ## WebSocket Connection
77
+
78
+ The chat connection uses Pusher WebSocket protocol with the following details:
79
+ - Auto-reconnection on disconnection
80
+ - Handles connection lifecycle
81
+ - Parses incoming chat events
82
+
83
+ ### Handling WebSocket Events
84
+
85
+ The WebSocket connection automatically handles:
86
+ - Connection establishment
87
+ - Channel subscription
88
+ - Message parsing
89
+ - Error handling
90
+ - Reconnection logic
91
+
92
+ ## Error Handling
93
+
94
+ Chat methods may throw:
95
+ - `ValueError` for invalid inputs
96
+ - `Exception` for API/WebSocket errors
97
+
98
+ Example:
99
+ ```python
100
+ try:
101
+ await api.connect_to_chatroom("invalid_username")
102
+ except ValueError as e:
103
+ print("Invalid username:", e)
104
+ except Exception as e:
105
+ print("Connection error:", e)
106
+ ```