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.2.tar.gz (88.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_webhook-0.0.2-py3-none-any.whl (15.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiogram_webhook-0.0.2.tar.gz
  • Upload date:
  • Size: 88.3 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.2.tar.gz
Algorithm Hash digest
SHA256 3a59587967c05de2db0f1e5632d89847f07e89b0a726ea2d10c4b06162088644
MD5 044a5021d6fa4d958f9f421cee8b9299
BLAKE2b-256 ed150145bae1cb83e064d960a1f8af0f181509d3243f2870c507d455e90c53d8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiogram_webhook-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 15.1 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 89636ae040fce67995be65e37080bf658f9a1b2e1eb5b8d9dee6b8162409acaa
MD5 f7c1d4312b1c41393691c4a4f02783f8
BLAKE2b-256 0076e581b65a431b04296cb0d342759a6b701b8695443b44c9513868ad41b7f7

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