toptl-aiogram
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:
- Registers a middleware on
dp.update.middlewarethat records unique user / group / channel IDs from every update (messages, callbacks, chat_member, …). - Hooks an
AsyncAutoposterinto the dispatcher's startup/shutdown events — it flushes stats every 30 min, only when counts changed. - Returns a
TopTLPluginhandle 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.
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| toptl_aiogram-0.1.0.tar.gz | 5.8 kB | Without provenance | Details for toptl_aiogram-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toptl_aiogram-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for toptl_aiogram-0.1.0-py3-none-any.whl |
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
|
Security for toptl-aiogram 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.