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

Drop-in middlewares for aiogram v3 with batteries included - Protect your Telegram bots from spam, abuse, and unwanted behavior with powerful middleware and storage backends.

✨ Features

  • Auth bootstrap with pluggable resolver → expose data["user_context"] without locking you to a DB.
  • Blocking: deny early if user is blocked; auto-sync block/unblock via my_chat_member, with on_block / on_unblock hooks.
  • Debouncing: suppress duplicate messages/callbacks within a window.
  • Throttling: per-user/handler scopes; notifier hook for UX.
  • Backends: memory (single worker) or redis (multi-worker), with configurable redis_prefix.
  • Setup helper: Sentinel.setup(dp, cfg) wires recommended order and membership router.
  • 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_sentinel import Sentinel, SentinelConfig

# 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
)

# Setup with one call - wires all middleware in recommended order
sentinel = Sentinel(config=config)
dp.message.middleware(sentinel.middleware)

# Your handlers now have access to user context
@dp.message()
async def handle_message(message, data):
    user_context = data["user_context"]  # Available after auth middleware
    await message.answer(f"Hello {user_context['username']}!")

# 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.0.tar.gz (261.9 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.0-py3-none-any.whl (23.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiogram_sentinel-0.1.0.tar.gz
  • Upload date:
  • Size: 261.9 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.0.tar.gz
Algorithm Hash digest
SHA256 7416681c464082050e0384ee494a236d8776dfc45359e2749e403d558c5c3438
MD5 5a6ed15c61beee6b39558c791afb4965
BLAKE2b-256 a67f51a458e3746d905c6d7d00400a6b23e7d7cc586615a693435a4689dece82

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_sentinel-0.1.0.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.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aiogram_sentinel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 556b4c36641acfe2ccb204bd4d52b3974d1f6df84cad076142bea52c1ef3e99f
MD5 f3a0a84e11ba9ae0774fef920f033a18
BLAKE2b-256 37a70da0a00311fd34efcb0807d3d0b8001e706ce53fc9088a43ee4a63c8c366

See more details on using hashes here.

Provenance

The following attestation bundles were made for aiogram_sentinel-0.1.0-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