toptl
The official Python SDK for TOP.TL — post stats, check votes, and manage vote webhooks for your Telegram bot, channel, or group listed on top.tl.
Install
pip install toptl
Requires Python 3.9+. Depends on httpx for transport.
Quickstart
Get an API key at https://top.tl/profile → API Keys. Scope the key to your listing and the operations you need (listing:read, listing:write, votes:read, votes:check).
from toptl import TopTL
client = TopTL("toptl_xxx")
# Fetch a listing
listing = client.get_listing("mybot")
print(listing.title, listing.vote_count)
# Post stats on a listing you own
client.post_stats(
"mybot",
member_count=5_000,
group_count=1_200,
channel_count=300,
)
# Reward users who voted
check = client.has_voted("mybot", user_id=123456789)
if check.voted:
grant_premium_access(user_id=123456789)
Async
Same surface, asyncio-native:
import asyncio
from toptl import AsyncTopTL
async def main():
async with AsyncTopTL("toptl_xxx") as client:
stats = await client.get_global_stats()
print(stats.channels, stats.groups, stats.bots)
asyncio.run(main())
Autoposter
For long-running bot processes, the SDK ships with a background autoposter that calls post_stats on an interval and only hits the API when the stats actually changed:
from toptl import TopTL, Autoposter
client = TopTL("toptl_xxx")
poster = Autoposter(
client,
"mybot",
callback=lambda: {"member_count": get_user_count()},
interval_seconds=30 * 60, # every 30 min
only_on_change=True,
)
poster.start()
For cron-style one-shots, skip the autoposter and call client.post_stats(...) directly.
Async version is AsyncAutoposter(async_client, ..., callback=async_fn).
Vote webhooks
Register a URL TOP.TL will POST to whenever someone votes for your listing:
client.set_webhook(
"mybot",
url="https://mybot.example.com/toptl-vote",
reward_title="30-day premium", # shown to the voter
)
# Send a test request to verify your endpoint
result = client.test_webhook("mybot")
print(result.success, result.status_code)
The webhook payload contains the voting user (userId, firstName, username), the listing, and a timestamp.
Batch stats
Post stats for up to 25 listings in one request:
client.batch_post_stats([
{"username": "bot1", "member_count": 1200},
{"username": "bot2", "member_count": 5400},
])
Error handling
Every API error raises a subclass of TopTLError:
from toptl import TopTL, AuthenticationError, NotFoundError, RateLimitError, ValidationError
try:
client.post_stats("mybot", member_count=5000)
except AuthenticationError:
... # bad key, or missing scope
except NotFoundError:
... # listing does not exist
except RateLimitError:
... # back off and retry
except ValidationError:
... # payload rejected — see exc.response_body
License
MIT — see LICENSE.
Metadata
Release files for toptl 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| toptl-0.1.1.tar.gz | 9.2 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| toptl-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 22.3 kB
Release files / toptl-0.1.1.tar.gz
| Download URL | toptl-0.1.1.tar.gz |
|---|---|
| Size | 9.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a081bf40cb4d5483b2dc5efced58c58b2aa25dd632bcae6437e46834fbdeb44c
|
|
BLAKE2b-256 checksum How to use checksums |
8fd877ad0561975ddaf0bb79703ec53a8683da72d3706c4f5d8f6fc13f86002f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|
Release files / toptl-0.1.1-py3-none-any.whl
| Download URL | toptl-0.1.1-py3-none-any.whl |
|---|---|
| Size | 13.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
d28284c4e280d66be8ae1a6b755800034f6eab08bfc616d36537b0db9e2c4df0
|
|
BLAKE2b-256 checksum How to use checksums |
b10a7da254bd1af1eb34f94d38155c3e4200b7d314db088e437e25265b38474d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.9.6
|