A modern, production-ready framework for building scalable Telegram bots with Aiogram 3.x
Project description
Boundless-Aiogram ๐
Boundless-Aiogram is a modern, production-ready framework/template for building scalable Telegram bots with Aiogram 3.x. It provides a clean, structured architecture with built-in support for async/await, database migrations, FSM, and more.
โจ Features
- โก Modern async/await syntax with Aiogram 3.x
- ๐ SQLAlchemy async ORM for database operations
- ๐ Alembic migrations for database versioning
- ๐ Modular architecture with organized handlers, middlewares, and filters
- ๐ฏ FSM (Finite State Machine) support for conversation flows
- ๐ก๏ธ Built-in middleware for authentication and rate limiting
- โ๏ธ Configuration management with environment variables
- ๐ Comprehensive logging system with file rotation
- ๐งช Test-ready structure with dedicated test directory
- ๐จ Modern CLI with beautiful output and progress indicators
๐ Installation
Install Boundless-Aiogram via pip:
pip install boundless-aiogram
๐ฆ Quick Start
Create a new bot project with a single command:
boundless new mybot
Navigate to your project and set up:
cd mybot
cp .env.example .env
# Edit .env and add your BOT_TOKEN
python main.py
That's it! Your bot is now running.
๐๏ธ Project Structure
Boundless-Aiogram generates a clean, organized project structure:
mybot/
โโโ bot/
โ โโโ handlers/ # Message and callback handlers
โ โ โโโ commands.py # Command handlers (/start, /help)
โ โ โโโ messages.py # Text message handlers
โ โ โโโ callbacks.py # Callback query handlers
โ โโโ middlewares/ # Custom middlewares
โ โ โโโ auth.py # Authentication middleware
โ โ โโโ throttling.py # Rate limiting middleware
โ โโโ filters/ # Custom filters
โ โ โโโ custom.py # Custom filter examples
โ โโโ keyboards/ # Keyboard layouts
โ โ โโโ inline.py # Inline keyboards
โ โ โโโ reply.py # Reply keyboards
โ โโโ states/ # FSM states
โ โโโ user.py # User conversation states
โโโ database/
โ โโโ models/ # Database models
โ โ โโโ base.py # Base model class
โ โ โโโ user.py # User model
โ โโโ database.py # Database configuration
โโโ core/
โ โโโ config.py # Configuration management
โ โโโ logging.py # Logging setup
โโโ utils/ # Helper functions
โ โโโ helpers.py # Utility functions
โโโ migrations/ # Alembic database migrations
โโโ tests/ # Unit tests
โโโ logs/ # Log files
โโโ main.py # Bot entry point
โโโ .env.example # Example environment variables
โโโ .gitignore
โโโ requirements.txt
โโโ README.md
๐ง Configuration
Configure your bot using environment variables in .env:
# Telegram Bot Configuration
BOT_TOKEN=your_bot_token_here
# Database Configuration
DATABASE_URL=sqlite+aiosqlite:///./bot_database.db
# Optional: PostgreSQL
# DATABASE_URL=postgresql+asyncpg://user:password@localhost/dbname
# Admin User IDs (comma-separated)
ADMIN_IDS=123456789,987654321
๐ Usage Examples
Adding a New Command Handler
Create or edit bot/handlers/commands.py:
from aiogram import Router
from aiogram.filters import Command
from aiogram.types import Message
router = Router()
@router.message(Command("hello"))
async def cmd_hello(message: Message):
await message.answer(f"Hello, {message.from_user.first_name}!")
Creating Custom Middleware
Edit bot/middlewares/auth.py:
from typing import Callable, Dict, Any, Awaitable
from aiogram import BaseMiddleware
from aiogram.types import Message
class AuthMiddleware(BaseMiddleware):
async def __call__(
self,
handler: Callable[[Message, Dict[str, Any]], Awaitable[Any]],
event: Message,
data: Dict[str, Any]
) -> Any:
# Your authentication logic here
user_id = event.from_user.id
# Check if user is authorized
return await handler(event, data)
Using FSM States
Define states in bot/states/user.py:
from aiogram.fsm.state import State, StatesGroup
class RegistrationStates(StatesGroup):
waiting_for_name = State()
waiting_for_age = State()
waiting_for_email = State()
Use in handlers:
from aiogram.fsm.context import FSMContext
from bot.states.user import RegistrationStates
@router.message(Command("register"))
async def start_registration(message: Message, state: FSMContext):
await state.set_state(RegistrationStates.waiting_for_name)
await message.answer("What's your name?")
@router.message(RegistrationStates.waiting_for_name)
async def process_name(message: Message, state: FSMContext):
await state.update_data(name=message.text)
await state.set_state(RegistrationStates.waiting_for_age)
await message.answer("How old are you?")
๐๏ธ Database Management
Creating Migrations
After modifying your models:
alembic revision --autogenerate -m "Added new field"
Applying Migrations
alembic upgrade head
Rolling Back
alembic downgrade -1
๐งช Testing
Run tests using pytest:
pytest tests/
๐ CLI Commands
boundless new <project_name> # Create a new bot project
boundless help # Show help information
๐ค Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
๐ License
This project is licensed under the MIT License.
๐ Links
๐ก Support
If you find this project helpful, consider giving it a โญ on GitHub!
For issues and feature requests, please use the GitHub issue tracker.
Built with โค๏ธ for the Telegram bot development community
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file boundless_aiogram-1.0.7.tar.gz.
File metadata
- Download URL: boundless_aiogram-1.0.7.tar.gz
- Upload date:
- Size: 11.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2a0f59c4823558e4c36afca9fa57abf54347fa7274c7c1f77e5fa661deaa7ba
|
|
| MD5 |
faded08ed6b986f49ebdc718ba4bb942
|
|
| BLAKE2b-256 |
323e0f13e1f3a8e74dbf56dd89eb29d142fbe09ff7c94e69eb1b52a242baefac
|
File details
Details for the file boundless_aiogram-1.0.7-py3-none-any.whl.
File metadata
- Download URL: boundless_aiogram-1.0.7-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dfa485439f337fcabb16989e0cde8bb70c6461b7d1a806de309791e478ee2bac
|
|
| MD5 |
337173ba6e6dd83f956ad78467b9cec1
|
|
| BLAKE2b-256 |
3412b75ee54c77f1e72eb6c0e140d33e2219cd258f6f5c225c23e290b65b9167
|