A python library for integrating webhook support with multiple web frameworks in aiogram. Organizes bot operation via webhooks for both single and multi-bot setups.
Project description
aiogram-webhook
aiogram-webhook is a Python library for seamless webhook integration with multiple web frameworks in aiogram. It enables both single and multi-bot operation via webhooks, with flexible routing and security features.
✨ Features
- 🧱 Modular and extensible webhook engine
- 🔀 Flexible routing (static and token-based)
- 🤖 Supports single and multi-bot setups
- ⚡ FastAPI adapters out of the box
- 🔒 Security best practices: secret tokens, IP checks
- 🧩 Easy to extend with custom adapters and routing
🚀 Installation
uv add aiogram-webhook
# or
pip install aiogram-webhook
⚡ Quick Start
Single Bot Example (FastAPI)
import uvicorn
from contextlib import asynccontextmanager
from fastapi import FastAPI
from aiogram import Bot, Dispatcher, Router
from aiogram.filters import CommandStart
from aiogram.types import Message
from aiogram_webhook import SimpleEngine, FastApiWebAdapter
from aiogram_webhook.routing import PathRouting
router = Router()
@router.message(CommandStart())
async def start(message: Message):
await message.answer("OK")
dispatcher = Dispatcher()
dispatcher.include_router(router)
bot = Bot("BOT_TOKEN_HERE")
engine = SimpleEngine(
dispatcher,
bot,
web_adapter=FastApiWebAdapter(),
routing=PathRouting(url="/webhook"),
)
@asynccontextmanager
async def lifespan(app: FastAPI):
engine.register(app)
await engine.set_webhook(
drop_pending_updates=True,
allowed_updates=("message", "callback_query"),
)
await engine.on_startup()
yield
await engine.on_shutdown()
app = FastAPI(lifespan=lifespan)
if __name__ == "__main__":
uvicorn.run("main:app", host="0.0.0.0", port=8080)
Multi-Bot Example (FastAPI)
Each bot is configured in Telegram with its own webhook URL: https://example.com/webhook/<BOT_TOKEN>
from aiogram import Dispatcher
from aiogram.client.default import DefaultBotProperties
from aiogram_webhook import TokenEngine, FastApiWebAdapter
from aiogram_webhook.routing import PathRouting
dispatcher = Dispatcher()
engine = TokenEngine(
dispatcher,
web_adapter=FastApiWebAdapter(),
routing=PathRouting(url="/webhook/{bot_token}", param="bot_token"),
bot_settings={
"default": DefaultBotProperties(parse_mode="HTML"),
},
)
Usage is the same:
engine.register(app)
await engine.set_webhook(...)
await engine.on_startup()
await engine.on_shutdown()
🛣️ Routing
PathRouting defines where Telegram sends updates:
- Static path:
PathRouting(url="/webhook")
- Token-based path:
PathRouting(url="/webhook/{bot_token}", param="bot_token")
🛡️ Security
writings...
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_webhook-0.0.1.tar.gz.
File metadata
- Download URL: aiogram_webhook-0.0.1.tar.gz
- Upload date:
- Size: 88.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
179a8e45ef44e0e528738eead7c13a8605ee0c204e103bf7d2b5f721ec1c89ec
|
|
| MD5 |
f5a670c657532c257b113fe685d15661
|
|
| BLAKE2b-256 |
dc40a1a8baafb16205336771b975021d9f14cd85e86ac7684d73240b53f7e893
|
File details
Details for the file aiogram_webhook-0.0.1-py3-none-any.whl.
File metadata
- Download URL: aiogram_webhook-0.0.1-py3-none-any.whl
- Upload date:
- Size: 15.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5d5b8d8f02f0f31a00817688ab63a1bd99874d88bd1dfb5387d4850267dcc16c
|
|
| MD5 |
cf40c128ca902c6975cc7c25a6f206a8
|
|
| BLAKE2b-256 |
e20f6d81fd6b6db73afa9cd853d0ff334fbc94c5e09f7b8932e2de3e2c75a519
|