An open API service indexing awesome lists of open source software.

https://github.com/timnekk/copier-telegram-bot

πŸš€ Copier Template for Telegram Bot using Aiogram, Postgres, Redis, Docker, Coolify Ready
https://github.com/timnekk/copier-telegram-bot

aiogram copier-template database docker docker-compose poerty postgresql pydantic python redis ruff sqlalchemy telegram telegram-bot telegrambot template uv

Last synced: 5 months ago
JSON representation

πŸš€ Copier Template for Telegram Bot using Aiogram, Postgres, Redis, Docker, Coolify Ready

Awesome Lists containing this project

README

          


Telegram Bot Template







Copier





Python 3.9 - 3.13





Linted by Ruff






Apache License 2.0



## πŸš€ Quickstart

Ensure [uv](https://docs.astral.sh/uv/getting-started/installation/) is installed, then create a new Telegram bot project with:

```bash
uvx --with copier-templates-extensions copier copy --trust -r HEAD gh:TimNekk/copier-telegram-bot ~/path/to/your/project
```

## ✨ Features

Built with [Copier](https://copier.readthedocs.io/), this template lets you toggle features during setup - choose what you need and generate files instantly! Ready for [Docker](https://www.docker.com/) 🐳 and [Coolify](https://coolify.io/) ☁️ deployment.

#### Core Infrastructure

- [x] [**`Docker Compose`**](https://docs.docker.com/compose/) 🐳 Launch bot + services with one command
- [x] [**`Python 3.9–3.13`**](https://www.python.org/) 🐍 Choose your Python version easily
- [x] [**`uv`**](https://docs.astral.sh/uv/) πŸš€ Fast dependency management powered by Rust
- [x] [**`Poetry`**](https://python-poetry.org/) πŸ“¦ Manage dependencies safely with virtual environments
- [x] [**`pip`**](https://pip.pypa.io/) πŸ“œ Classic Python package installer

#### Telegram Bot Framework

- [x] [**`Aiogram`**](https://docs.aiogram.dev/) ⚑ Modern async bot framework with state management
- [x] [**`Aiogram Dialog`**](https://github.com/Tishka17/aiogram_dialog) πŸ–ΌοΈ Create menus and interactive interfaces
- [x] [**`Redis`**](https://redis.io/) ❀️ Keep bot data safe between restarts

#### Database & ORM

- [x] [**`PostgreSQL`**](https://www.postgresql.org/) 🐘 Powerful database for complex projects
- [x] [**`SQLAlchemy`**](https://www.sqlalchemy.org/) πŸ› οΈ Work with databases using Python code
- [x] [**`Alembic`**](https://alembic.sqlalchemy.org/) ⏳ Track and apply database changes easily

#### Middlewares

- [x] [**`Dependency Injection`**](https://docs.aiogram.dev/en/latest/dispatcher/middlewares.html) πŸ’‰ Share tools/data across bot handlers
- [x] [**`Throttling`**](https://docs.aiogram.dev/en/latest/dispatcher/middlewares.html) πŸ›‘ Stop spam with automatic speed limits
- [x] [**`Database Sessions`**](https://docs.sqlalchemy.org/en/20/orm/session_basics.html) ♻️ Auto-manage database connections
- [x] [**`Loguru`**](https://github.com/Delgan/loguru) πŸ“œ Simple logging with colors and fun

#### Tooling

- [x] [**`Pydantic Settings`**](https://docs.pydantic.dev/latest/concepts/pydantic_settings/) βœ… Safe config management with type checking
- [x] [**`Dynaconf`**](https://www.dynaconf.com/) βš™οΈ Configs for dev/test/prod environments
- [x] [**`Ruff`**](https://docs.astral.sh/ruff/) πŸͺΆ Super-fast code linting and cleanup
- [x] [**`Justfile`**](https://just.systems/) πŸͺ„ Short commands for complex tasks
- [x] [**`Cache Decorator`**](https://pypi.org/project/orjson/) ⚑ Speed up functions with Redis caching

## πŸ“‚ Project Structure

The **fully-featured** generated project can be found in the [example/](./example) directory.

Below is the folder structure of the generated project:

```sh
.
β”œβ”€β”€ bot # Main directory for the bot's source code
β”‚ β”œβ”€β”€ cache # Contains caching-related modules
β”‚ β”‚ β”œβ”€β”€ redis.py # Module for Redis-based caching functionality
β”‚ β”‚ └── serialization.py # Handles serialization and deserialization for cached data
β”‚ β”‚
β”‚ β”œβ”€β”€ core # Core components of the bot
β”‚ β”‚ β”œβ”€β”€ loader.py # Initializes and loads core components of the bot
β”‚ β”‚ └── settings.py # Configuration and settings for the bot
β”‚ β”‚
β”‚ β”œβ”€β”€ database # Database-related modules and models
β”‚ β”‚ β”œβ”€β”€ models # Directory for database model definitions
β”‚ β”‚ β”‚ └── base.py # Base class for database models
β”‚ β”‚ └── database.py # Database connection
β”‚ β”‚
β”‚ β”œβ”€β”€ dialogs # Dialog flow and interaction logic
β”‚ β”‚ └── example # Example implementation of dialogs
β”‚ β”‚ β”œβ”€β”€ dialogs.py # Defines dialogs
β”‚ β”‚ β”œβ”€β”€ getters.py # Retrieves data required for dialogs
β”‚ β”‚ └── handlers.py # Handles user interactions within dialogs
β”‚ β”‚
β”‚ β”œβ”€β”€ filters/ # Custom filters for handling specific bot commands or messages
β”‚ β”‚
β”‚ β”œβ”€β”€ handlers # General handlers for bot events
β”‚ β”‚ └── start.py # Handler for the /start command
β”‚ β”‚
β”‚ β”œβ”€β”€ keyboards # Defines inline and reply keyboards for user interaction
β”‚ β”‚ β”œβ”€β”€ inline # Inline keyboards
β”‚ β”‚ └── default_commands.py # Defualt commands setup
β”‚ β”‚
β”‚ β”œβ”€β”€ middleware # Middleware modules to extend bot behavior
β”‚ β”‚ β”œβ”€β”€ database.py # Middleware to manage database interactions during eventxs
β”‚ β”‚ β”œβ”€β”€ dependency.py # Dependency injection middleware for shared resources
β”‚ β”‚ β”œβ”€β”€ logger.py # Middleware to log events
β”‚ β”‚ └── throttling.py # Middleware to handle rate-limiting of requests
β”‚ β”‚
β”‚ β”œβ”€β”€ services/ # Auxiliary services with business logic
β”‚ β”‚
β”‚ β”œβ”€β”€ __main__.py # Entry point to run the bot application
β”‚ └── states.py # FMS states
β”‚
β”œβ”€β”€ migrations # Database migration files (managed by Alembic)
β”‚ β”œβ”€β”€ versions/ # Directory containing individual migration scripts
β”‚ β”œβ”€β”€ env.py # Alembic environment configuration file
β”‚ └── script.py.mako # Template for generating new migration scripts
β”‚
β”œβ”€β”€ .dockerignore # Specifies files and directories to ignore in Docker builds
β”œβ”€β”€ .gitignore # Specifies files and directories to ignore in Git version control
β”œβ”€β”€ .python-version # Python version specification file for version managers like pyenv
β”œβ”€β”€ .env # Environment variable settings file
β”œβ”€β”€ .template.env # Template file for environment variables
β”œβ”€β”€ alembic.ini # Alembic configuration file for database migrations
β”œβ”€β”€ compose.yaml # Docker Compose configuration file for multi-container setups
β”œβ”€β”€ Dockerfile # Instructions to build a Docker image for the application
β”œβ”€β”€ entrypoint.sh # Script executed as the container's entry point
β”œβ”€β”€ justfile # Task runner configuration file (for `just` command automation)
β”œβ”€β”€ pyproject.toml # Python project metadata and dependencies configuration (PEP-518)
β”œβ”€β”€ README.md # Documentation readme file describing the project
└── uv.lock # Lock file generated by a dependency manager
```

## πŸ“– Usage

Before using the **Copier Telegram Bot** template, ensure you have the following installed:

- **Copier**: Refer to the [installation guide](https://copier.readthedocs.io/en/latest/#installation).
- **Copier Templates Extensions**: Refer to the [repository](https://github.com/copier-org/copier-templates-extensions?tab=readme-ov-file#installation) for installation instructions.

Once these prerequisites are installed, you're ready to use the template!

```bash
copier copy --trust -r HEAD gh:TimNekk/copier-telegram-bot ~/path/to/your/project
```

Copier will ask you a lot of questions. Answer them to properly generate the template.

## πŸ—ΊοΈ Roadmap

Help shape the future! Planned improvements:

- [ ] [**`Bot Internationalization`**](https://docs.aiogram.dev/en/latest/dispatcher/i18n.html) 🌐 Support multiple languages for global audiences
- [ ] [**`Prompts Internationalization`**](https://github.com/aiogram/aiogram) πŸ“‹ Translate copier prompts
- [ ] [**`Dependabot`**](https://github.com/dependabot) πŸ€– Add dependencies auto-update to generated project for security and freshness
- [ ] [**`Testing`**](https://docs.pytest.org/) βœ… Add testing framework
- [ ] [**`Flake8`**](https://flake8.pycqa.org/) / [**`wemake`**](https://wemake-python-styleguide.readthedocs.io/en/latest/) 🧹 Alternative strict linting for code quality fans

*Got ideas? Star ⭐ the repo or open an issue to collaborate!* πŸš€

## ⭐ Star History





Star History Chart

## πŸ‘· Contributing

- For a small change, just send a PR.
- For bigger changes open an issue for discussion before sending a PR.
- PR should have:
- Test case
- Documentation
- Example (If it makes sense)

## πŸ“ License

Distributed under the Apache License 2.0. See [`LICENSE`](./LICENSE.md) for more information.