balthon 0.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,274 @@
1
+ Metadata-Version: 2.4
2
+ Name: balthon
3
+ Version: 0.1.0
4
+ Summary: An asynchronous Python library for building bots for the Bale messenger.
5
+ Author-email: SAUMS <balthonSupport@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/saums-1391/balthon
8
+ Project-URL: Repository, https://github.com/saums-1391/balthon
9
+ Project-URL: Issues, https://github.com/saums-1391/balthon/issues
10
+ Keywords: bale,bale-messenger,bot,bot-api,async,asyncio
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Framework :: AsyncIO
13
+ Classifier: Intended Audience :: Developers
14
+ Classifier: License :: OSI Approved :: MIT License
15
+ Classifier: Operating System :: OS Independent
16
+ Classifier: Programming Language :: Python :: 3
17
+ Classifier: Programming Language :: Python :: 3.9
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Topic :: Communications :: Chat
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Requires-Python: >=3.9
25
+ Description-Content-Type: text/markdown
26
+ Requires-Dist: httpx>=0.24.0
27
+ Requires-Dist: fastapi>=0.100.0
28
+ Requires-Dist: uvicorn[standard]>=0.23.0
29
+
30
+ # Balthon
31
+
32
+ **Balthon** is an asynchronous Python library for building bots for the [Bale](https://bale.ai) messenger.
33
+
34
+ It provides an async client, update handlers, filters, message and user models, keyboard helpers, state management, and methods for interacting with the Bale Bot API.
35
+
36
+ ## Features
37
+
38
+ - Asynchronous API client built on `httpx`
39
+ - Long-polling support
40
+ - Optional built-in webhook server
41
+ - Update handlers and composable filters
42
+ - Message, user, chat, callback-query, and media models
43
+ - Reply and inline keyboard helpers
44
+ - Per-user update queues and rate limiting
45
+ - Lightweight state manager with expiration
46
+ - Bale API operations for messages, chats, files, members, stickers, and payments
47
+
48
+ ## Requirements
49
+
50
+ - Python 3.9 or newer
51
+ - An active Bale bot token
52
+
53
+ ## Installation
54
+
55
+ Install the package from PyPI:
56
+
57
+ ```bash
58
+ pip install balthon
59
+ ```
60
+
61
+ For webhook mode, install the optional dependencies:
62
+
63
+ ```bash
64
+ pip install "balthon[webhook]"
65
+ ```
66
+
67
+ ## Quick start
68
+
69
+ Create a bot in Bale and obtain its token. Then create a Python file:
70
+
71
+ ```python
72
+ from balthon import BotClient, filters
73
+
74
+ bot = BotClient("YOUR_BOT_TOKEN")
75
+
76
+
77
+ @bot.on_update(filters.command("start"))
78
+ async def start_handler(update):
79
+ await bot.reply("Hello! Welcome to my bot.")
80
+
81
+
82
+ bot.run()
83
+ ```
84
+
85
+ Replace `YOUR_BOT_TOKEN` with your bot token.
86
+
87
+ ## Handling updates
88
+
89
+ Register handlers with `on_update`. You can pass one or more filters to decide which updates a handler receives.
90
+
91
+ ```python
92
+ from balthon import BotClient, filters
93
+
94
+ bot = BotClient("YOUR_BOT_TOKEN")
95
+
96
+
97
+ @bot.on_update(filters.text())
98
+ async def text_handler(update):
99
+ await bot.reply(f"You sent: {update.text}")
100
+
101
+
102
+ @bot.on_update(filters.photo())
103
+ async def photo_handler(update):
104
+ await bot.reply("I received a photo!")
105
+
106
+
107
+ bot.run()
108
+ ```
109
+
110
+ The library includes filters for common update types and conditions, including text, commands, private chats, groups, channels, photos, documents, audio, video, voice messages, stickers, callbacks, contacts, locations, membership status, user IDs, chat IDs, and state checks.
111
+
112
+ Filters can be combined with `&` (AND), `|` (OR), and `~` (NOT).
113
+
114
+ ```python
115
+ @bot.on_update(filters.private() & filters.text())
116
+ async def private_text_handler(update):
117
+ await bot.reply("This is a private text message.")
118
+ ```
119
+
120
+ ## Keyboards
121
+
122
+ Balthon provides helpers for reply and inline keyboards.
123
+
124
+ ```python
125
+ from balthon import BotClient, Button, KeyBoard, KeyBoardRow
126
+
127
+ bot = BotClient("YOUR_BOT_TOKEN")
128
+
129
+
130
+ @bot.on_update(filters.command("menu"))
131
+ async def menu_handler(update):
132
+ keyboard = KeyBoard(
133
+ KeyBoardRow(Button("Option 1"), Button("Option 2")),
134
+ resize=True,
135
+ )
136
+ await bot.reply("Choose an option:", markup=keyboard)
137
+
138
+
139
+ bot.run()
140
+ ```
141
+
142
+ For inline keyboards:
143
+
144
+ ```python
145
+ from balthon import InlineButton, InLineRow, InLineKeyboard
146
+
147
+ keyboard = InLineKeyboard(
148
+ InLineRow(InlineButton("Open Bale", url="https://bale.ai"))
149
+ )
150
+ ```
151
+
152
+ ## State management
153
+
154
+ Use `StateManager` to store temporary state for a user. States expire after the configured number of seconds.
155
+
156
+ ```python
157
+ from balthon import BotClient, StateManager, filters
158
+
159
+ bot = BotClient("YOUR_BOT_TOKEN")
160
+ states = StateManager()
161
+
162
+
163
+ @bot.on_update(filters.command("begin"))
164
+ async def begin(update):
165
+ await states.set_state_for(update, "waiting_for_name", expire=60)
166
+ await bot.reply("What is your name?")
167
+
168
+
169
+ @bot.on_update(filters.at_state(states, "waiting_for_name"))
170
+ async def receive_name(update):
171
+ name = update.text
172
+ await bot.reply(f"Nice to meet you, {name}!")
173
+ await states.clear_state_for(update)
174
+
175
+
176
+ bot.run()
177
+ ```
178
+
179
+ ## Webhook mode
180
+
181
+ Webhook mode uses FastAPI and Uvicorn. Install the optional dependencies first:
182
+
183
+ ```bash
184
+ pip install "balthon[webhook]"
185
+ ```
186
+
187
+ Then start the client with `use_webhook=True`:
188
+
189
+ ```python
190
+ from balthon import BotClient, filters
191
+
192
+ bot = BotClient("YOUR_BOT_TOKEN", use_webhook=True)
193
+
194
+ @bot.on_update(filters.text())
195
+ async def text_handler(update):
196
+ await bot.reply(update.text)
197
+
198
+ bot.run(host="0.0.0.0", port=8000, webhook_path="/webhook")
199
+ ```
200
+
201
+ Configure your Bale bot webhook to point to the publicly reachable endpoint for your server. Make sure your deployment, network, and webhook URL are configured appropriately.
202
+
203
+ ## Async applications
204
+
205
+ If your application already runs an asyncio event loop, use `await bot.start()` instead of `bot.run()`:
206
+
207
+ ```python
208
+ import asyncio
209
+ from balthon import BotClient
210
+
211
+ bot = BotClient("YOUR_BOT_TOKEN")
212
+
213
+
214
+ async def main():
215
+ await bot.start()
216
+
217
+
218
+ asyncio.run(main())
219
+ ```
220
+
221
+ ## API overview
222
+
223
+ The package exports the main client as `BotClient` (also available as `Client` and `BotConnect`), along with:
224
+
225
+ - `filters` and `Filter`
226
+ - `StateManager`
227
+ - Keyboard and button helpers
228
+ - Update, message, user, chat, media, and payment models
229
+ - Bale API response models
230
+ - `ActionsEnum`
231
+ - Balthon-specific exception classes
232
+
233
+ See the source code and exported names in [`balthon/__init__.py`](balthon/__init__.py) for the complete public API.
234
+
235
+ ## Error handling
236
+
237
+ Balthon defines exception classes for common client and API errors, including:
238
+
239
+ - `BalthonError`
240
+ - `BaleError`
241
+ - `APIError`
242
+ - `NetworkError`
243
+ - `InvalidTokenError`
244
+ - `AuthenticationError`
245
+ - `RateLimitError`
246
+ - `InvalidRequestError`
247
+ - `UpdateError`
248
+ - `HandlerError`
249
+ - `FilterError`
250
+ - `StateError`
251
+
252
+ You can import these directly from `balthon`:
253
+
254
+ ```python
255
+ from balthon import APIError, NetworkError
256
+
257
+ try:
258
+ # Call a Balthon API method here.
259
+ pass
260
+ except NetworkError as error:
261
+ print(f"Network error: {error}")
262
+ except APIError as error:
263
+ print(f"Bale API error: {error}")
264
+ ```
265
+
266
+ ## Links
267
+
268
+ - **GitHub:** https://github.com/saums-1391/balthon
269
+ - **Issues:** https://github.com/saums-1391/balthon/issues
270
+ - **Email:** balthonSupport@gmail.com
271
+
272
+ ## License
273
+
274
+ This project is licensed under the MIT License. See [LICENSE](LICENSE) for details.
@@ -0,0 +1,4 @@
1
+ balthon-0.1.0.dist-info/METADATA,sha256=NAvanLvz_lNmbup7Sql49YldN-kE5nIfHREHMpjBDEk,7041
2
+ balthon-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
3
+ balthon-0.1.0.dist-info/top_level.txt,sha256=AbpHGcgLb-kRsJGnwFEktk7uzpZOCcBY74-YBdrKVGs,1
4
+ balthon-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+