Aiobale
Modern, fast, fully asynchronous Python framework for Bale Messenger.
📖 Interactive Documentation • 📦 PyPI Package • 🚀 Quickstart • ✨ Features
🌟 Overview
Aiobale is a high-performance, asynchronous Python library built on top of asyncio, WebSockets, and Protocol Buffers for the Bale Messenger platform. Designed with inspiration from modern bot frameworks like aiogram, it allows developers to build userbots, official bots, automation tools, and group management services with minimal resource usage and complete type safety.
✨ Key Features
- ⚡ Fully Asynchronous: Built natively on Python
asynciofor non-blocking I/O and high concurrency. - 🧠 Finite State Machine (FSM): Multi-step conversational form management with
State,StatesGroup, andFSMContext. - 🛡️ Middlewares Pipeline: Intercept and process events before/after handlers with
BaseMiddleware. - ⌨️ Fluent Keyboard Builders: Chainable creation of Inline and Reply keyboards with dynamic grid formatting.
- 🔮 Magic Filter (
F): Powerful expression-based event filtering (e.g.F.text.startswith("/start"),F.chat.type == ChatType.GROUP). - 🔀 Modular Routing: Organize complex bots across multiple files using
Routerand sub-routers. - 🛡️ Full RPC Coverage (79+ Methods): Complete access to Messaging, Groups, Channels, Contacts, Presence, Reactions, and File APIs.
- 📁 Fast Media Upload & Download: Automated chunked file streaming with binary support.
- 🔐 Flexible Authentication: Interactive CLI phone login, persistent session files (
.bale), direct JWT token support, and headless Docker readiness. - 🧩 100% Type Annotated: Powered by Pydantic v2 for data validation and complete IDE autocompletion.
- 🧪 Battle-Tested: Automated CI pipeline verifying compatibility from Python 3.8 to 3.14.
📦 Installation
# Install officially from PyPI
pip install aiobale-py
# Or install the latest development version directly from GitHub
pip install git+https://github.com/aminmadaniofficial/aiobale.git
Note: The package is installed as
aiobale-py, while you import it in your Python code directly asimport aiobaleorfrom aiobale import Client, Dispatcher, F.
🚀 Quickstart
Create your first bot in less than 5 minutes:
import asyncio
from aiobale import Client, Dispatcher, F
from aiobale.types import Message
from aiobale.filters import IsText
dp = Dispatcher()
client = Client(dp, session_file="my_bot")
@dp.message(F.text == "/start")
async def start_handler(message: Message):
await message.reply("Hello! Welcome to Aiobale 🚀")
@dp.message(IsText())
async def echo_handler(message: Message):
await message.reply(f"You said: {message.text}")
async def main():
print("Connecting to Bale Messenger...")
await client.start()
if __name__ == "__main__":
asyncio.run(main())
When you run this script for the first time in your terminal, it will interactively prompt for your phone number and SMS verification code, then store the session in my_bot.bale for automatic reconnects.
🎯 Code Examples
1. Finite State Machine (FSM) Form
from aiobale import Client, Dispatcher, F
from aiobale.fsm import State, StatesGroup, FSMContext
from aiobale.types import Message
class Registration(StatesGroup):
name = State()
age = State()
dp = Dispatcher()
client = Client(dp, session_file="fsm_bot")
@dp.message(F.text == "/register")
async def start_register(msg: Message, state: FSMContext):
await state.set_state(Registration.name)
await msg.reply("Please enter your name:")
@dp.message(Registration.name)
async def process_name(msg: Message, state: FSMContext):
await state.update_data(name=msg.text)
await state.set_state(Registration.age)
await msg.reply("Great! Now enter your age:")
@dp.message(Registration.age)
async def process_age(msg: Message, state: FSMContext):
data = await state.get_data()
name = data.get("name")
age = msg.text
await state.clear()
await msg.reply(f"Registration complete! Name: {name}, Age: {age}")
if __name__ == "__main__":
client.run()
2. Group Moderation & Anti-Link Bot
import re
from aiobale import Client, Dispatcher, F
from aiobale.types import Message
from aiobale.enums import ChatType
dp = Dispatcher()
client = Client(dp, session_file="mod_bot")
LINK_REGEX = re.compile(r"(https?://|ble\.ir/|t\.me/|eitaa\.com/)")
@dp.message(F.chat.type == ChatType.GROUP)
async def delete_links(msg: Message):
if msg.text and LINK_REGEX.search(msg.text):
await msg.delete()
@dp.message(F.text == "/ban", F.chat.type == ChatType.GROUP)
async def ban_user(msg: Message, client: Client):
if msg.replied_to:
await client.kick_user(msg.chat.id, msg.replied_to.sender_id)
await msg.answer("User kicked from group.")
if __name__ == "__main__":
client.run()
📚 Comprehensive Documentation
The repository includes a modern, web-based interactive documentation website with zero emojis, custom Lucide icons, Dark/Light modes, live search (Ctrl+K), and reference guides for all 79+ methods:
🏛️ Project Origin & Acknowledgements
This project is built upon the foundational work of the original aiobale library created by Alireza Jahani (Enalite LD).
It has been modernized, heavily refactored, debugged, and is now actively maintained with automated CI/CD and comprehensive docs by Amin Madani.
📄 License
Distributed under the MIT License. See LICENSE for more details.
Metadata
Release files for aiobale-py 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| aiobale_py-0.3.2.tar.gz | 136.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| aiobale_py-0.3.2-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 373.2 kB
Release files / aiobale_py-0.3.2.tar.gz
| Download URL | aiobale_py-0.3.2.tar.gz |
|---|---|
| Size | 136.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d2387afc3617620820c9e25ff27eb32ac9ec1bd393414e34928097e2a136752f
|
|
BLAKE2b-256 checksum How to use checksums |
496af9dc203af9795f246fa491319f0ef1d8ae5e09762225b0134504b6a784c6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.
Transparency logRelease files / aiobale_py-0.3.2-py3-none-any.whl
| Download URL | aiobale_py-0.3.2-py3-none-any.whl |
|---|---|
| Size | 236.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
589d5fc151ed95add61147dfc8e7e1f8d88121e66b0871139ee1b95a401461b0
|
|
BLAKE2b-256 checksum How to use checksums |
eafaba74d18253d13cc946f04b89ab18a139b2a5cf1a173009c1b561e5d9eb1a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 24, 2026.
Transparency log