Modern template for development Telegram bots on based Aiogram 3.18.0. Includes all needed components for create scalable and supported bots.
- Framework: Aiogram 3.18.0
- Database:
- PostgreSQL (asyncpg 0.30.0)
- SQLite (aiosqlite 0.21.0)
- ORM: SQLAlchemy 2.0.39
- Migrations: Alembic 1.15.1
- Localization: Babel 2.17.0 (i18n)
- Configuration: Pydantic 2.10.6
- Logging: Main features Built-in log rotation system
- Docker: Ready-made configuration for deployment
- Python 3.8+
- Docker (опционально)
- Git
- Clone repository:
git clone https://github.com/zhandos256/templateaiogram
cd templateaiogram
- Create virtual environment and install requirements:
python -m venv venv
source venv/bin/activate # для Linux/Mac
# или
venv\Scripts\activate # для Windows
pip install -r requirements.txt
- Create file
.env
and configure the environment variables:
BOT_TOKEN=your_bot_token
DB_TYPE=sqlite # или postgres
POSTGRES_DB_URL=postgresql+asyncpg://postgres:postgres@localhost:5432/postgres # если используете PostgreSQL
DEBUG=True # режим отладки
- Start migrations:
alembic upgrade head
- Start bot:
python src/main.py
- Create file
.env
based on the example above, set up the environment variables:
# Bot settings
BOT_TOKEN=your_bot_token
DEBUG=True
# Database settings
DB_TYPE=sqlite # или postgres
POSTGRES_DB_URL=postgresql+asyncpg://postgres:postgres@postgres:5432/postgres
# PostgreSQL settings (если используется PostgreSQL)
POSTGRES_USER=postgres
POSTGRES_PASSWORD=postgres
POSTGRES_DB=postgres
- Build and start container:
docker-compose build
docker-compose up
Note: All settings are now taken from the file
.env
. This makes it easy to change the configuration without changing the `docker-compose.yml'.
- Extract the translation strings:
pybabel extract --input-dirs=. -o locales/messages.pot
- Create a new translation file:
pybabel init -i locales/messages.pot -d locales -D messages -l kk
-
Edit the file
locales/kk/LC_MESSAGES/messages.po
-
Compile the translations:
pybabel compile -d locales -D messages
src/
├── config/ # App configuration
├── database/ # Work with database
├── filters/ # Custom Filters
├── handlers/ # Handlers
├── keyboards/ # Keyboards
├── locales/ # Localization files
├── middleware/ # Middlewares
├── services/ # Business logic
└── utils/ # Auxiliary functions
- By default used Sqlite database
- For use PostgreSQL change
DB_TYPE=postgres
in.env
file - Database URL PostgreSQL:
postgresql+asyncpg://postgres:postgres@localhost:5432/postgres
- Logs are saved in the directory
logs/
- Log format:
YYYY-MM-DD.log
- Debugging mode:
DEBUG=True
в.env
- By default: russioan language
- Translation files:
locales/
- Message domain:
messages
- Copy
.env.example
to.env
:
cp .env.example .env
- Set up environment variables in
.env
:
BOT_TOKEN=your_bot_token
DEBUG=True
DB_TYPE=sqlite # or postgres
- Start with
.env
configuration:
docker-compose --env-file .env up -d
Important:
.env
files don't should be in repository- Add them to
.gitignore
MIT License