Skip to main content

Professional CLI scaffolding tool for aiogram 3.x Telegram bots

Project description

๐Ÿค– Aiogram Part

Professional CLI scaffolding tool for Telegram bots with aiogram 3.x

5 daqiqada production-ready bot yarating! Database, Redis, Testing, Deployment - hammasi tayyor! ๐Ÿš€

PyPI version Python 3.10+ Aiogram 3.22.0 License: MIT


โšก Quick Start

# Install
pip install aiogram-part

# Create bot with database (SQLite/PostgreSQL/MySQL)
mkdir my-bot && cd my-bot
aiogram-part init-project --with-db --type postgresql

# Setup
cp .env.example .env  # Edit BOT_TOKEN
make install          # Install dependencies

# Run
make run             # Or: docker-compose up -d

Tayyor! Bot ishlayapti! โœ…


๐ŸŽฏ Features

Feature Description Commands
๐Ÿ—๏ธ Clean Architecture Scoped handlers (user/admin), services, filters 20+ commands
๐Ÿ—„๏ธ Database SQLite/PostgreSQL/MySQL + Aerich migrations init-project --with-db --type
โšก Redis Caching & FSM storage with fallback Auto-configured
๐Ÿณ Docker Database-specific docker-compose docker-compose up
๐Ÿงช Testing pytest + fixtures + test generator aiogram-part test
๐Ÿ” Health Check Environment validator with auto-fix aiogram-part check --fix
๐Ÿ“Š Statistics Project metrics with Rich tables aiogram-part stats
๐ŸŒ Webhook Setup & status commands aiogram-part webhook
๐Ÿš€ Deployment Systemd service generator aiogram-part deploy
๐Ÿ“ Logging Rotating logs with levels Built-in
๐ŸŒ i18n Multi-language with Babel aiogram-part i18n
๐Ÿ”’ Type Safe Pydantic settings + OOP keyboards All templates

๐Ÿ“ฆ Commands

๐Ÿš€ Project Initialization

# Basic project
aiogram-part init-project

# With database (choose type)
aiogram-part init-project --with-db --type sqlite      # SQLite (default)
aiogram-part init-project --with-db --type postgresql  # PostgreSQL + Docker
aiogram-part init-project --with-db --type mysql       # MySQL + Docker

Creates 38+ directories, 41+ files: handlers, services, filters, keyboards, middlewares, models, tests, Docker configs.


๐ŸŽฏ Code Generators

Handlers - Command, Message, Callback

aiogram-part handler user command start          # /start command
aiogram-part handler admin command stats         # Admin-only command
aiogram-part handler user message photo          # Photo messages
aiogram-part handler user callback confirm       # Callback handler

Creates: handlers/{users|admins}/{commands|messages|callbacks}/name.py + auto-registers router

Models - Database models with Tortoise ORM

aiogram-part model User                          # Model only
aiogram-part model Product --with-crud           # Model + CRUD operations

Creates: database/models/name.py + optional database/crud/name.py

Keyboards - OOP Builder pattern

aiogram-part keyboard --scope user --build-keyboard inline menu
aiogram-part keyboard --scope admin --build-keyboard reply settings --str-params status
aiogram-part keyboard --scope common --build-keyboard inline language \
  --str-params lang --int-params user_id

Creates: keyboards/{users|admins|common}/name.py with Builder pattern class

Filters - Custom filters

# Common filters (IsAdmin, IsPremium, etc)
aiogram-part filter --scope common --type common admin

# Callback filters (structured button data)
aiogram-part filter --scope user --type callback product \
  --str-params action --int-params product_id

Creates: filters/{users|admins|common}/{common|callback}/name.py

Middlewares - Request interceptors

aiogram-part middleware --scope user throttling --types message
aiogram-part middleware --scope admin logger --types all
aiogram-part middleware --scope common auth --types message callback_query

Creates: middlewares/{users|admins|common}/name.py

Services - Business logic layer

aiogram-part service --scope user payment        # User payment service
aiogram-part service --scope admin analytics     # Admin analytics
aiogram-part service --scope common notification # Common notification

Creates: services/{users|admins|common}/name.py with service class

States - FSM state machines

aiogram-part state Registration                  # User registration flow
aiogram-part state OrderCheckout                 # Checkout process

Creates: states/name.py with StatesGroup

Validators - Input validation

aiogram-part validator phone --type regex        # Phone number regex
aiogram-part validator email --type custom       # Custom email validator

Creates: utils/validators/name.py

Enums - Database enums

aiogram-part enum UserRole --values admin --values user --values moderator
aiogram-part enum OrderStatus --values pending --values completed

Creates: database/enums/name.py with enum class


๐Ÿ—„๏ธ Database Management (Aerich - Prisma-like)

aiogram-part db migrate              # Initialize migrations
aiogram-part db update model         # Auto-detect model changes
aiogram-part db upgrade              # Apply migrations
aiogram-part db downgrade            # Rollback migration
aiogram-part db history              # View migration history
aiogram-part db heads                # Show current version
aiogram-part db reset                # Reset database
aiogram-part db generate description # Generate custom migration
aiogram-part db inspect              # Inspect database schema

๐Ÿงช Testing & Quality

Test Generator

aiogram-part test --type handler start           # Handler test
aiogram-part test --type service payment         # Service test
aiogram-part test --type generic utils           # Generic test

Creates: tests/{handlers|services}/test_name.py with pytest fixtures

Environment Checker

aiogram-part check                               # Check project health
aiogram-part check --fix                         # Auto-fix issues

Checks: dependencies, .env file, migrations, Python version

Project Statistics

aiogram-part stats                               # Rich table with metrics

Shows: handlers, services, models, filters, middlewares, states, files, LOC


๐ŸŒ Deployment & Operations

Webhook Management

aiogram-part webhook setup https://bot.example.com  # Configure webhook
aiogram-part webhook status                          # Check status

Systemd Service

aiogram-part deploy --user botuser --python /path/to/python3

Generates systemd service file for Linux servers

Multi-language Support

aiogram-part i18n                                # Setup i18n + Babel

Creates: locales/ + middleware + Makefile commands


๐Ÿ“ Project Structure

bot/
โ”œโ”€โ”€ handlers/
โ”‚   โ”œโ”€โ”€ users/                # User handlers
โ”‚   โ”‚   โ”œโ”€โ”€ commands/         # /start, /help
โ”‚   โ”‚   โ”œโ”€โ”€ messages/         # Text, photo messages
โ”‚   โ”‚   โ””โ”€โ”€ callbacks/        # Callback queries
โ”‚   โ”œโ”€โ”€ admins/              # Admin-only handlers
โ”‚   โ””โ”€โ”€ errors/              # Error handlers
โ”œโ”€โ”€ services/
โ”‚   โ”œโ”€โ”€ users/               # User business logic
โ”‚   โ”œโ”€โ”€ admins/              # Admin business logic
โ”‚   โ””โ”€โ”€ common/              # Shared services
โ”œโ”€โ”€ filters/
โ”‚   โ”œโ”€โ”€ users/               # User filters
โ”‚   โ”œโ”€โ”€ admins/              # Admin filters
โ”‚   โ””โ”€โ”€ common/              # Shared filters
โ”œโ”€โ”€ keyboards/
โ”‚   โ”œโ”€โ”€ users/               # User keyboards (OOP)
โ”‚   โ”œโ”€โ”€ admins/              # Admin keyboards
โ”‚   โ””โ”€โ”€ common/              # Shared keyboards
โ”œโ”€โ”€ middlewares/
โ”‚   โ”œโ”€โ”€ users/               # User middlewares
โ”‚   โ”œโ”€โ”€ admins/              # Admin middlewares
โ”‚   โ””โ”€โ”€ common/              # Global middlewares
โ”œโ”€โ”€ database/
โ”‚   โ”œโ”€โ”€ models/              # Tortoise ORM models
โ”‚   โ”œโ”€โ”€ crud/                # CRUD operations
โ”‚   โ”œโ”€โ”€ enums/               # Database enums
โ”‚   โ””โ”€โ”€ migrations/          # Aerich migrations
โ”œโ”€โ”€ states/                  # FSM states
โ”œโ”€โ”€ utils/
โ”‚   โ”œโ”€โ”€ validators/          # Input validators
โ”‚   โ”œโ”€โ”€ decorators/          # Custom decorators
โ”‚   โ””โ”€โ”€ formatters/          # Data formatters
โ”œโ”€โ”€ tests/
โ”‚   โ”œโ”€โ”€ handlers/            # Handler tests
โ”‚   โ”œโ”€โ”€ services/            # Service tests
โ”‚   โ””โ”€โ”€ conftest.py          # pytest fixtures
โ”œโ”€โ”€ core/                    # Bot initialization
โ”œโ”€โ”€ config/                  # Settings & logging
โ”œโ”€โ”€ locales/                 # i18n translations
โ”œโ”€โ”€ docker-compose.yml       # Database + Redis
โ”œโ”€โ”€ Dockerfile               # Bot container
โ”œโ”€โ”€ Makefile                 # Dev commands
โ””โ”€โ”€ .env.example             # Environment template

๐Ÿ’ก Quick Examples

E-commerce Bot

aiogram-part init-project --with-db --type postgresql
aiogram-part model Product --with-crud
aiogram-part model Order --with-crud
aiogram-part enum OrderStatus --values pending --values paid --values shipped
aiogram-part service --scope user payment
aiogram-part handler user command catalog
aiogram-part keyboard --scope user --build-keyboard inline products --int-params page
aiogram-part filter --scope user --type callback product --str-params action --int-params product_id
aiogram-part test --type handler catalog

Multi-language Bot

aiogram-part init-project --with-db
aiogram-part i18n
aiogram-part model User --with-crud
aiogram-part state Registration
aiogram-part handler user command start
aiogram-part keyboard --scope common --build-keyboard inline language --int-params user_id
aiogram-part validator phone --type regex
make translate

Admin Panel Bot

aiogram-part init-project --with-db
aiogram-part filter --scope common --type common admin
aiogram-part handler admin command stats
aiogram-part handler admin command users
aiogram-part service --scope admin analytics
aiogram-part keyboard --scope admin --build-keyboard inline admin_panel
aiogram-part test --type service analytics

More examples: EXAMPLES.md


๐Ÿ› ๏ธ Development Workflow

# Setup
make install          # Install dependencies
make dev             # Install dev tools

# Development
make run             # Run bot locally
make test            # Run tests
aiogram-part check   # Health check
aiogram-part stats   # View project stats

# Database
aiogram-part db update model    # Detect changes
aiogram-part db upgrade         # Apply migrations
aiogram-part db history         # View history

# Production
aiogram-part webhook setup https://bot.example.com
aiogram-part deploy --user botuser
docker-compose up -d

๐Ÿณ Docker Deployment

# SQLite (no external database needed)
docker-compose up -d

# PostgreSQL (recommended for production)
aiogram-part init-project --with-db --type postgresql
cp .env.example .env
docker-compose up -d  # Starts bot + postgres + redis

# View logs
docker-compose logs -f bot

๐Ÿ“š Documentation

  • ๐Ÿ“– Full README - Complete documentation
  • ๐Ÿ’ก Examples - Real bot examples
  • โ“ FAQ - Common questions๐Ÿ“„ License

MIT ยฉ Sattorbek


๐Ÿ”— Links


โญ Star on GitHub โ€ข ๐Ÿ“– Documentation โ€ข ๐Ÿ’ก Examples

Made with โค๏ธ for aiogram community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiogram_part-1.0.1.tar.gz (28.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiogram_part-1.0.1-py3-none-any.whl (35.4 kB view details)

Uploaded Python 3

File details

Details for the file aiogram_part-1.0.1.tar.gz.

File metadata

  • Download URL: aiogram_part-1.0.1.tar.gz
  • Upload date:
  • Size: 28.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for aiogram_part-1.0.1.tar.gz
Algorithm Hash digest
SHA256 1027e0746fd677ffae97b7cb16910a4575505f16c6d1840720075f0106e592d6
MD5 b1301f444beb57f18a07116f38b4e2d2
BLAKE2b-256 29a1fa5787b9b37fb3a97e8485f3ece848c4ee4249690ab184ca37c51c0bb307

See more details on using hashes here.

File details

Details for the file aiogram_part-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: aiogram_part-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 35.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.12

File hashes

Hashes for aiogram_part-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b501aa94a2735275a99cede4f1888ddc39def5ef8adf5fe89d400cdf65fadfd2
MD5 38f665900e6369fe0ef5b16a507a6e77
BLAKE2b-256 1f47a407775f269667254c32948c1a1a8dac274cd12c539c7f032db57b3dfc8e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page