[go: up one dir, main page]

Skip to content

Scalable asynchronous telegram bot template, based on aiogram and tortoise-orm

License

Notifications You must be signed in to change notification settings

smkthat/aiogram-tortoise-bot-template

Repository files navigation

aiogram-tortoise-bot-template

Scalable asynchronous telegram bot template, based on aiogram and tortoise-orm

GitHub last commit project version GitHub Actions Workflow Status codecov

aiogram framework python version

GitHub License


Current stack and futures

  • 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

Poetry build-system

Poetry

This project uses poetry. To run the project, use this set of commands:

poetry install

The lock command allows you to fix dependencies by updating the poetry.lock file:

poetry lock

Be 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-update

Synchronize the virtual environment with the .lock file:

poetry lock --sync

You can read more about poetry here: https://python-poetry.org/

Run project

For local running, use:

poetry run python -m src

Configuration

This 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/

Pre-commit

To install pre-commit simply run inside the shell:

pre-commit install

pre-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 --verbose

You can read more about pre-commit here: https://pre-commit.com/

Migrations

For manual first initial database use:

aerich init-db

If you want to migrate your database, you should run the following commands:

# Upgrade database to the last migration.
aerich upgrade

Reverting migrations

If you want to revert migrations, you should run:

aerich downgrade

Migration generation

To generate migrations you should run:

aerich migrate

Tests

For run tests locally, use:

poetry run pytest -vv ./tests

Running with coverage:

poetry run pytest -vv ./tests --cov

Releases

No releases published

Packages

No packages published

Languages