For more information, see the documentation here: https://topggpy.rtfd.io.
The community-maintained Python SDK for Top.gg.
$ pip install topggpyimporttopggimportostoken=os.getenv('TOPGG_TOKEN')
asserttokenisnotNone, 'Missing TOPGG_TOKEN environment variable.'client=topgg.Client(token)project=awaitclient.get_self()vote=awaitclient.get_vote(topgg.UserSource.DISCORD, 661200758510977084)vote=awaitclient.get_vote(topgg.UserSource.TOPGG, 8226924471638491136)fromdatetimeimportdatetimefirst_page=awaitclient.get_votes(datetime(2026, 1, 1))
forvoteinfirst_page:
print(vote)
second_page=awaitfirst_page.next()
forvoteinsecond_page:
print(vote)
third_page=awaitsecond_page.next()commands= [command.to_dict() forcommandinawaitbot.tree.fetch_commands()]
awaitclient.post_commands(commands)# Array of application commands that# can be serialized to Discord API's raw JSON format.awaitclient.post_commands(
[
{
'id': '1',
'type': 1,
'application_id': '1',
'name': 'test',
'description': 'command description',
'default_member_permissions': '',
'version': '1',
}
]
)widget_url=topgg.Widget.large(topgg.Platform.DISCORD, topgg.ProjectType.BOT, 1026525568344264724)widget_url=topgg.Widget.votes(topgg.Platform.DISCORD, topgg.ProjectType.BOT, 1026525568344264724)widget_url=topgg.Widget.owner(topgg.Platform.DISCORD, topgg.ProjectType.BOT, 1026525568344264724)widget_url=topgg.Widget.social(topgg.Platform.DISCORD, topgg.ProjectType.BOT, 1026525568344264724)With express:
importtopggfromaiohttpimportwebimportossecret=os.getenv('TOPGG_WEBHOOK_SECRET')
assertsecretisnotNone, 'Missing TOPGG_WEBHOOK_SECRET environment variable.'# POST /webhookwebhooks=topgg.Webhooks('/webhook', secret)
@webhooks.on(topgg.PayloadType.TEST)asyncdeftest_listener(payload: topgg.TestPayload, trace: str) ->web.Response:
print(payload)
returnweb.Response(status=204)
awaitwebhooks.start()