toptl-ptb
Official TOP.TL plugin for python-telegram-bot. One call wires up autoposted bot stats, vote-gated commands, and webhook helpers — all on top of the toptl SDK.
Install
pip install toptl-ptb
Python 3.9+. Pulls in toptl>=0.1.1 and python-telegram-bot>=21.0.
Quick start
from telegram.ext import ApplicationBuilder, CommandHandler
from toptl import AsyncTopTL
from toptl_ptb import setup_toptl, vote_required
app = ApplicationBuilder().token("BOT_TOKEN").build()
client = AsyncTopTL("toptl_xxx")
# One line installs the tracker + autoposter on the Application.
plugin = setup_toptl(app, client, "mybot")
@vote_required(plugin, vote_url="https://top.tl/mybot")
async def premium(update, context):
await update.message.reply_text("Thanks for voting!")
app.add_handler(CommandHandler("premium", premium))
app.run_polling()
setup_toptl does three things:
- Adds a low-priority
TypeHandlerthat records unique user / group / channel IDs from every update. - Schedules a
JobQueuetask that flushes those counts to TOP.TL every 30 min — only when they changed, so you're not burning API quota on idle minutes. - Returns a
TopTLPluginhandle you use for vote checks and manual flushes.
Vote gating
The @vote_required(plugin) decorator short-circuits the handler and replies with a prompt when the user hasn't voted:
@vote_required(plugin, message="Vote to unlock this: https://top.tl/mybot")
async def premium(update, context):
...
For checks inside existing logic:
if await plugin.has_voted(update.effective_user.id):
...
Both paths fail-open — network errors never block your handler, they just count as "not voted" and log at ERROR level.
Tuning the autoposter
plugin = setup_toptl(
app, client, "mybot",
interval_seconds=15 * 60, # flush every 15 min instead of 30
first_seconds=5, # first flush 5s after startup
handler_group=-1, # override the default -100 group
)
To flush manually — for example from a graceful-shutdown hook:
async def post_shutdown(application):
await plugin.post_now()
await client.aclose()
app.post_shutdown = post_shutdown
Requirements
python-telegram-bot[job-queue]>=21.0— the[job-queue]extra enables the autoposter. Without it you can still callplugin.post_now()from your own schedule (e.g. an existingapscheduler).- Python 3.9 or newer.
License
MIT.
Part of the TOP.TL developer ecosystem. Issues and contributions: top-tl/ptb.
Metadata
Release files for toptl-ptb 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_ptb-0.1.0.tar.gz | 6.2 kB | Without provenance | Details for toptl_ptb-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| toptl_ptb-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for toptl_ptb-0.1.0-py3-none-any.whl |
Total release size: 13.6 kB
Release files / toptl_ptb-0.1.0.tar.gz
| Download URL | toptl_ptb-0.1.0.tar.gz |
|---|---|
| Size | 6.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
74d5481ffe4b5d3880b6675b35bbf51ecd20cfa755774fb982065b6cd5fd61c9
|
|
BLAKE2b-256 checksum How to use checksums |
7914dd32be8f47571a64ad0c1e58dbd96848016c3634aa0239a2dd8b491f84d5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / toptl_ptb-0.1.0-py3-none-any.whl
| Download URL | toptl_ptb-0.1.0-py3-none-any.whl |
|---|---|
| Size | 7.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07b67f72b7ed73bbfafc4da5fb93fdf605c5f724b360f198817d3dd38c579feb
|
|
BLAKE2b-256 checksum How to use checksums |
486cca1a7ff2a7d8bcea496faf77fbaf86b5dd60516b4008d8b12847ad6115d4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Security for toptl-ptb 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.