Skip to main content

toptl-aiogram

PyPI version Python versions Downloads License aiogram TOP.TL

Official TOP.TL plugin for aiogram 3. One call wires up autoposted bot stats, vote-gated handlers, and webhook helpers — all on top of the toptl SDK.

Install

pip install toptl-aiogram

Python 3.9+. Pulls in toptl>=0.1.1 and aiogram>=3.0.

Quick start

import asyncio
from aiogram import Bot, Dispatcher
from aiogram.filters import Command
from aiogram.types import Message
from toptl import AsyncTopTL
from toptl_aiogram import setup_toptl, vote_required

async def main():
    bot = Bot("BOT_TOKEN")
    dp = Dispatcher()
    client = AsyncTopTL("toptl_xxx")

    # One call installs the middleware + autoposter, tied to dp's
    # startup/shutdown hooks — no background task bookkeeping for you.
    plugin = setup_toptl(dp, client, "mybot")

    @dp.message(Command("premium"))
    @vote_required(plugin, vote_url="https://top.tl/mybot")
    async def premium(message: Message):
        await message.answer("Thanks for voting!")

    await dp.start_polling(bot)

asyncio.run(main())

setup_toptl does three things:

  1. Registers a middleware on dp.update.middleware that records unique user / group / channel IDs from every update (messages, callbacks, chat_member, …).
  2. Hooks an AsyncAutoposter into the dispatcher's startup/shutdown events — it flushes stats every 30 min, only when counts changed.
  3. Returns a TopTLPlugin handle you use for vote checks and manual flushes.

Vote gating

@dp.message(Command("premium"))
@vote_required(plugin, message="Vote first: https://top.tl/mybot")
async def premium(message: Message):
    ...

Works on message and callback-query handlers. Network or auth failures fall through as "not voted" and log at ERROR level — vote gates never brick your bot.

For checks inside existing logic:

@dp.message(Command("check"))
async def check(message: Message):
    if await plugin.has_voted(message.from_user.id):
        await message.answer("You voted, thanks!")
    else:
        await message.answer("Please vote at https://top.tl/mybot")

The plugin handle is also injected into handler data under data["toptl"]:

async def handler(message: Message, toptl):  # aiogram reads the param name
    if await toptl.has_voted(message.from_user.id):
        ...

Tuning the autoposter

plugin = setup_toptl(
    dp, client, "mybot",
    interval_seconds=15 * 60,  # flush every 15 min instead of 30
)

Manual flush (e.g. before shutdown):

await plugin.post_now()

Requirements

  • aiogram>=3.0
  • Python 3.9+

License

MIT.


Part of the TOP.TL developer ecosystem. Issues and contributions: top-tl/aiogram.

Release files for toptl-aiogram 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for toptl-aiogram 0.1.0
File Size Uploaded
toptl_aiogram-0.1.0.tar.gz 5.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for toptl-aiogram 0.1.0
File Interpreter ABI Platform
toptl_aiogram-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 12.8 kB

Release files / toptl_aiogram-0.1.0.tar.gz

Download URL toptl_aiogram-0.1.0.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
cc8d27ff495f1dc987d70fc453d5806473b18771c9b373f671631f30225a7aba
BLAKE2b-256 checksum
How to use checksums
e3c6b54728f732b463dc5845b66a7bfd5bbb4f167f695f85679c0fcbdb101e12
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / toptl_aiogram-0.1.0-py3-none-any.whl

Download URL toptl_aiogram-0.1.0-py3-none-any.whl
Size 6.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ba50fba9a03cf48a93287b4d75ebe117b3197b5a0edce138c737777d0a7ece99
BLAKE2b-256 checksum
How to use checksums
0748e4f1751d96ac151295912915ea364d2cd81c5c24a77bbb5e8a2dab068d63
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page