- 🔧 Aiogram
(v3.17)
for building Telegram bots with ease. - 🪴 Fluentogram a proper way to use an i18n mechanism with Aiogram3.
- 📊 SQLite for lightweight database storage using aiosqlite.
- 🔌 Alembic for database migrations.
- ⚡ Asyncio for asynchronous programming.
- 🛠️ Pydantic and Pydantic Settings for robust data validation and settings management.
- 🔮 SQLAlchemy for database ORM.
- 🎨 Loguru for advanced logging capabilities.
- ⚛ UV extremely fast Python package and project manager, written in Rust.
- Recommended Python version: 3.12
- Make sure to have UV installed
-
Clone the repository:
git clone https://github.com/haxgun/telegram-bot-template.git cd telegram-bot-template
-
Install dependencies:
uv init
-
Set up the virtual environment:
- Create a virtual environment:
uv venv
- Activate the virtual environment:
source ./venv/bin/activate
- Create a virtual environment:
-
Set up the environment variables:
- Create a
.env
file in the project root. - Add the necessary configurations (e.g.,
BOT_TOKEN
,ADMIN_IDS
).
- Create a
-
Run database migrations:
alembic revision --autogenerate -m "Initial revision" alembic upgrade head
-
Start the bot:
python3 -m bot.main
telegram-bot-template/
├── bot/
│ ├── __init__.py
│ ├── main.py # Main entry point
│ ├── config.py # Configuration settings
│ ├── handlers/ # Bot handlers ✋
│ ├── keyboards/ # Custom keyboards 🎹
│ ├── i18n/ # Internationalization 🌍
│ ├── middlewares/ # Custom middlewares 🔑
│ ├── services/ # Utility services 🔧
│ ├── migrations/ # Alembic migrations 🔄
│ │ ├── env.py # Environment variables 🌱
│ │ ├── script.py.mako # Alembic migration script 🔨
│ ├── database/ # Database files 📊
│ │ ├── database.py # Database setup 🗄️
│ │ ├── models.py # Database models 🧑💻
├── data/ # Data files 📂
│ ├── __init__.py
├── .env.example # Example environment variables 🌱
├── .gitignore # Ignored files 🚫
├── alembic.ini # Configuration file for Alembic ⚙️
├── LICENSE # License file 📜
├── pyproject.toml # Dependencies 📋
├── requirements.txt # Dependencies 🔌
└── README.md # Project documentation 📚
- Modular architecture for scalability.
- Asynchronous database operations with SQLite.
- Easy-to-use logging via Loguru.
- Seamless environment variable management with Pydantic Settings.
- Effortless database migrations with Alembic.
Ensure you have the following variables set in your .env
file:
BOT_TOKEN=your-telegram-bot-token
ADMIN_IDS=[AdminID1, AdminID2, AdminID3]
- Fork the repository.
- Create your feature branch:
git checkout -b feature-name
- Commit your changes:
git commit -m "Add feature"
- Push to the branch:
git push origin feature-name
- Open a pull request.
This project is licensed under the MIT License - see the LICENSE file for details.
🎉 Happy Coding! 🌟