Skip to main content

Command management library for aiogram v3

Project description

aiogram-cmds

CI PyPI Python versions License

Command management library for aiogram v3 - Manage Telegram bot commands with i18n support, user profiles, and dynamic scopes.

โœจ Features

  • Simple & Advanced Modes: Start simple, scale to complex configurations
  • i18n Integration: Built-in support for aiogram i18n with fallback handling
  • User Profiles: Dynamic command sets based on user status (guest, registered, etc.)
  • Multiple Scopes: Support for all Telegram command scopes (private, group, admin, etc.)
  • Auto-Setup: One-call setup with sensible defaults
  • Type-Safe: Full type hints and strict type checking
  • Production Ready: Comprehensive testing, CI/CD, and documentation

๐Ÿ“ฆ Installation

# Basic installation
pip install aiogram-cmds

# With Redis support (for multi-worker deployments)
pip install aiogram-cmds[redis]

โšก Quick Start

Auto-Setup (Recommended)

from aiogram import Bot, Dispatcher
from aiogram_cmds.auto_setup import setup_commands_auto

async def on_startup():
    # Automatically set up commands with sensible defaults
    command_manager = await setup_commands_auto(bot)
    # Commands are ready to use!

# Your handlers
@dp.message(Command("start"))
async def handle_start(message: Message):
    await message.answer("Welcome! Use /help to see available commands.")

Simple Mode

from aiogram import Bot, Dispatcher
from aiogram_cmds import CommandScopeManager, load_settings, build_translator_from_i18n

# Load settings from pyproject.toml or use defaults
settings = load_settings()
translator = build_translator_from_i18n(i18n)  # Your aiogram i18n instance

# Create manager
manager = CommandScopeManager(bot, settings=settings, translator=translator)

# Set up all command scopes
await manager.setup_all()

# Update user commands dynamically
await manager.update_user_commands(
    user_id=12345,
    is_registered=True,
    has_vehicle=False,
    user_language="en"
)

Advanced Mode

from aiogram_cmds import CmdsConfig, CommandDef, ProfileDef, ScopeDef, MenuButtonDef

# Define your command configuration
config = CmdsConfig(
    languages=["en", "ru", "es"],
    commands={
        "start": CommandDef(i18n_key="start.desc"),
        "help": CommandDef(i18n_key="help.desc"),
        "profile": CommandDef(i18n_key="profile.desc"),
        "admin": CommandDef(i18n_key="admin.desc"),
    },
    profiles={
        "guest": ProfileDef(include=["start", "help"]),
        "user": ProfileDef(include=["start", "help", "profile"]),
        "admin": ProfileDef(include=["start", "help", "profile", "admin"]),
    },
    scopes=[
        ScopeDef(scope="all_private_chats", profile="guest"),
        ScopeDef(scope="chat", chat_id=12345, profile="admin"),
    ],
    menu_button=MenuButtonDef(mode="commands"),
)

# Create manager with custom profile resolver
def my_profile_resolver(flags):
    if flags.is_admin:
        return "admin"
    elif flags.is_registered:
        return "user"
    return "guest"

manager = CommandScopeManager(
    bot, 
    config=config, 
    profile_resolver=my_profile_resolver
)
await manager.setup_all()

๐ŸŽฏ Use Cases

E-commerce Bot

# Different commands for different user states
profiles = {
    "visitor": ProfileDef(include=["start", "catalog", "help"]),
    "customer": ProfileDef(include=["start", "catalog", "cart", "orders", "help"]),
    "vip": ProfileDef(include=["start", "catalog", "cart", "orders", "vip_offers", "help"]),
}

Admin Bot

# Admin commands only for specific users
scopes = [
    ScopeDef(scope="all_private_chats", profile="user"),
    ScopeDef(scope="chat_member", chat_id=12345, user_id=67890, profile="admin"),
]

Multi-Language Bot

# Commands in multiple languages
config = CmdsConfig(
    languages=["en", "ru", "es", "fr"],
    commands={
        "start": CommandDef(i18n_key="commands.start"),
        "help": CommandDef(i18n_key="commands.help"),
    }
)

๐Ÿ“š Documentation

๐Ÿ‘‰ Full Documentation โ† Start here!

๐Ÿ—๏ธ Architecture

aiogram-cmds provides three levels of complexity:

  1. Auto-Setup: Zero configuration, works out of the box
  2. Simple Mode: Settings-based configuration with policies
  3. Advanced Mode: Full control with profiles, scopes, and custom resolvers
โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   Auto-Setup    โ”‚    โ”‚   Simple Mode    โ”‚    โ”‚  Advanced Mode  โ”‚
โ”‚                 โ”‚    โ”‚                  โ”‚    โ”‚                 โ”‚
โ”‚ setup_commands_ โ”‚    โ”‚ CmdsSettings +   โ”‚    โ”‚ CmdsConfig +    โ”‚
โ”‚ auto()          โ”‚    โ”‚ CommandPolicy    โ”‚    โ”‚ ProfileResolver โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
         โ”‚                       โ”‚                       โ”‚
         โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                                 โ”‚
                    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
                    โ”‚ CommandScopeMgr  โ”‚
                    โ”‚                  โ”‚
                    โ”‚ โ€ข setup_all()    โ”‚
                    โ”‚ โ€ข update_user()  โ”‚
                    โ”‚ โ€ข clear_user()   โ”‚
                    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿค Contributing

We welcome contributions! See our Contributing Guide for details.

Development Setup

# Clone the repository
git clone https://github.com/ArmanAvanesyan/aiogram-cmds.git
cd aiogram-cmds

# Set up development environment
uv venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
uv pip install -e ".[dev]"

# Run tests
uv run pytest

# Run linting
uv run ruff check .
uv run ruff format .

๐Ÿ’ฌ Community & Support

  • ๐Ÿ’ฌ Discussions - Questions, ideas, and community chat
  • ๐Ÿ› Issues - Bug reports and feature requests
  • ๐Ÿ“– Documentation - Complete guides and API reference

๐Ÿ”’ Security

For security issues, see SECURITY.md.

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

  • Built for aiogram v3 - Modern Telegram Bot API framework
  • Inspired by the need for robust command management in production environments

๐Ÿ“Š Project Status

  • โœ… Core Features: Command management, i18n, profiles, scopes
  • โœ… Documentation: Comprehensive guides and API reference
  • โœ… Testing: Unit, integration, and performance tests
  • โœ… CI/CD: Automated testing and deployment
  • ๐Ÿšง Examples: Working bot examples (in progress)
  • ๐Ÿ”ฎ Future: Rate limiting, caching, advanced analytics

Made with โค๏ธ for the 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_cmds-0.1.1.tar.gz (274.6 kB view details)

Uploaded Source

Built Distribution

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

aiogram_cmds-0.1.1-py3-none-any.whl (18.0 kB view details)

Uploaded Python 3

File details

Details for the file aiogram_cmds-0.1.1.tar.gz.

File metadata

  • Download URL: aiogram_cmds-0.1.1.tar.gz
  • Upload date:
  • Size: 274.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiogram_cmds-0.1.1.tar.gz
Algorithm Hash digest
SHA256 6b8d1f70f3c778adfd578ec2fb600cbd1c36e24cec31ae32926a1ab9c20411c6
MD5 937b12bb5cc6123964e93200319c3b53
BLAKE2b-256 87e1394a007e8ec77542bced906bf04181b46a77f89fada2555128759f8cc27a

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_cmds-0.1.1.tar.gz:

Publisher: release.yml on ArmanAvanesyan/aiogram-cmds

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file aiogram_cmds-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: aiogram_cmds-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 18.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for aiogram_cmds-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ed12a47fca23ef3e0eb41b5d261c62237268eaf4d9477895c01e822d69bdbf11
MD5 fb9e21227908376f51755a427866976d
BLAKE2b-256 70feb73630e9b7e0294e105fed3114528c64540f11750c45b7cb2fceb97296fc

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_cmds-0.1.1-py3-none-any.whl:

Publisher: release.yml on ArmanAvanesyan/aiogram-cmds

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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