Skip to main content

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

PyPI version License Tests Status Release Status Ask DeepWiki

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aiogram_webhook-0.0.3.tar.gz (11.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_webhook-0.0.3-py3-none-any.whl (15.2 kB view details)

Uploaded Python 3

File details

Details for the file aiogram_webhook-0.0.3.tar.gz.

File metadata

  • Download URL: aiogram_webhook-0.0.3.tar.gz
  • Upload date:
  • Size: 11.6 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

Hashes for aiogram_webhook-0.0.3.tar.gz
Algorithm Hash digest
SHA256 e780d954b47bb7f239536bb96c1e33c96adf22a8efff8debfbdffceb667dfef0
MD5 cfe901ba8e98005c48e250ed1f6d5ae5
BLAKE2b-256 35512b9ec0c9f169963b9b1198d637a37a9ee43be8f8c39f4b688972791c6628

See more details on using hashes here.

File details

Details for the file aiogram_webhook-0.0.3-py3-none-any.whl.

File metadata

  • Download URL: aiogram_webhook-0.0.3-py3-none-any.whl
  • Upload date:
  • Size: 15.2 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

Hashes for aiogram_webhook-0.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2956e975073e43ae04f5c09a8bb11df6967d47b05c9a63faab2e32fc601341de
MD5 0ab8734f61ee16e1562572e99fa2a1e0
BLAKE2b-256 5c9212a4e7f9667c65ed6e88e625837e4b72848cdf96909ffdccc725990af14a

See more details on using hashes here.

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