Command management library for aiogram v3
Project description
aiogram-cmds
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!
- Quickstart - Get started in 5 minutes
- Configuration - Complete configuration guide
- API Reference - Full API documentation
- Tutorials - Step-by-step guides
- Examples - Complete working examples
๐๏ธ Architecture
aiogram-cmds provides three levels of complexity:
- Auto-Setup: Zero configuration, works out of the box
- Simple Mode: Settings-based configuration with policies
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiogram_cmds-0.1.0.tar.gz.
File metadata
- Download URL: aiogram_cmds-0.1.0.tar.gz
- Upload date:
- Size: 265.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0cfdbaffc2350fb92e7cd98fc54df1784aba244d320522fb05c1764abfd43892
|
|
| MD5 |
2e59033589fb44ee907e8cd537959aed
|
|
| BLAKE2b-256 |
0781b1f1e23f5f306d2a6f2cda8f52502cb86c58bd7e0731177f6452a6f7d24b
|
Provenance
The following attestation bundles were made for aiogram_cmds-0.1.0.tar.gz:
Publisher:
release.yml on ArmanAvanesyan/aiogram-cmds
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiogram_cmds-0.1.0.tar.gz -
Subject digest:
0cfdbaffc2350fb92e7cd98fc54df1784aba244d320522fb05c1764abfd43892 - Sigstore transparency entry: 604823130
- Sigstore integration time:
-
Permalink:
ArmanAvanesyan/aiogram-cmds@e9703edc2db3495b93e913645899c815dbcf0026 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ArmanAvanesyan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e9703edc2db3495b93e913645899c815dbcf0026 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aiogram_cmds-0.1.0-py3-none-any.whl.
File metadata
- Download URL: aiogram_cmds-0.1.0-py3-none-any.whl
- Upload date:
- Size: 17.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a93c6e4e7457cb3664d3cfb2b1cf76a3e70b4db9d8785512f0daaba6d3aa2901
|
|
| MD5 |
86c4e36935cb7fdc3b7f93dd748cece5
|
|
| BLAKE2b-256 |
89e21cb5316571d7d1baa72bd5990bca9cfdac6f6e98d39d01a7d0f5641bcc0c
|
Provenance
The following attestation bundles were made for aiogram_cmds-0.1.0-py3-none-any.whl:
Publisher:
release.yml on ArmanAvanesyan/aiogram-cmds
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiogram_cmds-0.1.0-py3-none-any.whl -
Subject digest:
a93c6e4e7457cb3664d3cfb2b1cf76a3e70b4db9d8785512f0daaba6d3aa2901 - Sigstore transparency entry: 604823132
- Sigstore integration time:
-
Permalink:
ArmanAvanesyan/aiogram-cmds@e9703edc2db3495b93e913645899c815dbcf0026 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/ArmanAvanesyan
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@e9703edc2db3495b93e913645899c815dbcf0026 -
Trigger Event:
push
-
Statement type: