Skip to main content

Edge hygiene library for aiogram v3 with middlewares, router, and storage backends

Project description

aiogram-sentinel

CI PyPI Python License Ruff

Rate limiting and debouncing middleware for aiogram v3 - Protect your Telegram bots from spam and abuse with powerful middleware and storage backends.

✨ Features

  • Rate Limiting: Per-user/handler scopes with sliding window algorithm
  • Debouncing: Suppress duplicate messages/callbacks within a configurable window
  • Storage Backends: Memory (single worker) or Redis (multi-worker) with configurable prefixes
  • Decorators: @rate_limit and @debounce for easy handler configuration
  • Hooks: Optional on_rate_limited callback for custom user feedback
  • Setup Helper: Sentinel.setup(dp, cfg) wires middleware in recommended order
  • Typed, async-first, production-ready.

📦 Installation

# Basic installation
pip install aiogram-sentinel

# With Redis support
pip install aiogram-sentinel[redis]

⚡ Quick Start

from aiogram import Bot, Dispatcher
from aiogram.types import Message
from aiogram_sentinel import Sentinel, SentinelConfig, rate_limit, debounce

# Create bot and dispatcher
bot = Bot(token="YOUR_BOT_TOKEN")
dp = Dispatcher()

# Configure aiogram-sentinel
config = SentinelConfig(
    throttling_default_max=10,  # 10 messages per window
    throttling_default_per_seconds=60,  # 60 second window
    debounce_default_window=2,  # 2 second debounce
)

# Setup with one call - wires all middleware in recommended order
router, infra = await Sentinel.setup(dp, config)

# Your handlers with protection
@router.message()
@rate_limit(5, 60)  # 5 messages per minute
@debounce(1.0)      # 1 second debounce
async def handle_message(message: Message):
    await message.answer(f"Hello! Your message: {message.text}")

# Start your bot
await dp.start_polling(bot)

📚 Documentation

🤝 Contributing

See CONTRIBUTING.md for development guidelines and setup instructions.

🔒 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 bot protection in production environments

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_sentinel-0.1.1.tar.gz (234.3 kB view details)

Uploaded Source

Built Distribution

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

aiogram_sentinel-0.1.1-py3-none-any.whl (17.0 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for aiogram_sentinel-0.1.1.tar.gz
Algorithm Hash digest
SHA256 fe5e906bd1add2a512942652e9d29bf561d1dd3c264063dabd100d0a15a932a0
MD5 0326876d2a382080398ff6c10120535a
BLAKE2b-256 ccba5b01ecd554aa75d80680bcbdbee8252de0c85205568bde2d86a4d19825b9

See more details on using hashes here.

Provenance

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

Publisher: release.yml on ArmanAvanesyan/aiogram-sentinel

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_sentinel-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for aiogram_sentinel-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 46b39d6b2b0776eebe394c94d0b41505729736cfdeb8237640356af594c09b34
MD5 61a8f7bda9dc46f9638fd6b9d77c2376
BLAKE2b-256 2fa33fac561b1adc0a396384df07089be990159ae4c2979b0b96e68361e6446c

See more details on using hashes here.

Provenance

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

Publisher: release.yml on ArmanAvanesyan/aiogram-sentinel

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