Scalable asynchronous telegram bot template, based on aiogram and tortoise-orm
- Poetry dependency management
- Loguru
- Aiogram
- Aiogram-dialog
- Tortoise ORM and Aerich migrations with PostgreSQL database
- Linting with Ruff, Pylint, MyPy
- Pre-commit, tests workflow, Codecov analysis
- Docker and build workflows
- Redis for FSM, cache and storage
- Nats
This project uses poetry.
To run the project, use this set of commands:
poetry installThe lock command allows you to fix dependencies by updating the poetry.lock
file:
poetry lockBe careful!
By default, poetry lock will attempt to update all dependencies to the
latest valid versions.
To avoid this, use the --no-update option.
poetry lock --no-updateSynchronize the virtual environment with the .lock file:
poetry lock --syncYou can read more about poetry here: https://python-poetry.org/
For local running, use:
poetry run python -m srcThis application can be configured with environment variables.
You can create .env file in the root directory and place all
environment variables here.
All environment variables should start with "BOT_" prefix.
For example if you see in your "src/settings.py" a variable named like
random_parameter, you should provide the "BOT_RANDOM_PARAMETER"
variable to configure the value.
This behaviour can be changed by overriding env_prefix property
in src.settings.Settings.Config.
An example of .env file:
BOT_ENVIRONMENT="dev"
BOT_TOKEN="123456:Your_bot_token"
BOT_DB_HOST="localhost"You can read more about BaseSettings class here: https://pydantic-docs.helpmanual.io/usage/settings/
To install pre-commit simply run inside the shell:
pre-commit installpre-commit is very useful to check your code before publishing it.
It's configured using .pre-commit-config.yaml file.
By default, it runs:
ruff(formats & validates)black(formats your code);mypy(validates types);
Use for local running:
pre-commit run --all-files --verboseYou can read more about pre-commit here: https://pre-commit.com/
For manual first initial database use:
aerich init-dbIf you want to migrate your database, you should run the following commands:
# Upgrade database to the last migration.
aerich upgradeIf you want to revert migrations, you should run:
aerich downgradeTo generate migrations you should run:
aerich migrateFor run tests locally, use:
poetry run pytest -vv ./testsRunning with coverage:
poetry run pytest -vv ./tests --cov