Skip to main content
View on PyPi v1.0.0 Documentation Status

A simple API wrapper for Top.gg written in Python, supporting discord.py.

Installation

Install via pip (recommended)

pip3 install topggpy

Install from source

pip3 install git+https://github.com/top-gg/python-sdk/

Documentation

Documentation can be found here

Features

  • POST server count

  • GET bot info, server count, upvote info

  • GET all bots

  • GET user info

  • GET widgets (large and small) including custom ones. See docs.top.gg for more info.

  • GET weekend status

  • Built-in webhook to handle Top.gg votes

  • Automated server count posting

  • Searching for bots via the API

Additional information

  • Before using the webhook provided by this library, make sure that you have specified port open.

  • Optimal values for port are between 1024 and 49151.

  • If you happen to need help implementing topggpy in your bot, feel free to ask in the #development or #api channels in our Discord server.

Examples

Posting server count manually every 30 minutes:

from discord.ext import tasks

import topgg

# This example uses tasks provided by discord.ext to create a task that posts guild count to Top.gg every 30 minutes.

dbl_token = 'Top.gg token'  # set this to your bot's Top.gg token
bot.topggpy = topgg.DBLClient(bot, dbl_token)

@tasks.loop(minutes=30)
async def update_stats():
    """This function runs every 30 minutes to automatically update your server count."""
    try:
        await bot.topggpy.post_guild_count()
        print(f'Posted server count ({bot.topggpy.guild_count})')
    except Exception as e:
        print('Failed to post server count\n{}: {}'.format(type(e).__name__, e))

update_stats.start()

Using webhook:

import topgg

# This example uses topggpy's webhook system.
# The port must be a number between 1024 and 49151.

bot.topgg_webhook = topgg.WebhookManager(bot).dbl_webhook("/dblwebhook", "password")
bot.topgg_webhook.run(5000)  # this method can be awaited as well

@bot.event
async def on_dbl_vote(data):
    """An event that is called whenever someone votes for the bot on Top.gg."""
    if data["type"] == "test":
        # this is roughly equivalent to
        # return await on_dbl_test(data) in this case
        return bot.dispatch('dbl_test', data)

    print(f"Received a vote:\n{data}")

@bot.event
async def on_dbl_test(data):
    """An event that is called whenever someone tests the webhook system for your bot on Top.gg."""
    print(f"Received a test vote:\n{data}")

With autopost:

import topgg

# This example uses topggpy's autopost feature to post guild count to Top.gg every 30 minutes
# as well as the shard count if applicable.

dbl_token = 'Top.gg token'  # set this to your bot's Top.gg token
bot.topggpy = topgg.DBLClient(bot, dbl_token, autopost=True, post_shard_count=True)

@bot.event
async def on_autopost_success():
    print(f'Posted server count ({bot.topggpy.guild_count}), shard count ({bot.shard_count})')

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

topggpy-1.4.0.tar.gz (15.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

topggpy-1.4.0-py3-none-any.whl (19.5 kB view details)

Uploaded Python 3

File details

Details for the file topggpy-1.4.0.tar.gz.

File metadata

  • Download URL: topggpy-1.4.0.tar.gz
  • Upload date:
  • Size: 15.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for topggpy-1.4.0.tar.gz
Algorithm Hash digest
SHA256 75a2f3011a073c058238b740989155cc85598250ed605b788b5de28c4314ec04
MD5 d9716e98fbf7e3ee9747193d4cd5d54d
BLAKE2b-256 feaa45e9aafedf5065f6da0c1f5eae5b234d3ab5c8973febcd561aec3ecf4f4c

See more details on using hashes here.

File details

Details for the file topggpy-1.4.0-py3-none-any.whl.

File metadata

  • Download URL: topggpy-1.4.0-py3-none-any.whl
  • Upload date:
  • Size: 19.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.2 CPython/3.9.7

File hashes

Hashes for topggpy-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d0c9e329c6613d6a4889ad56295554e60440a5c5025d92ea3bf0b7a816dae27c
MD5 7f1372f533dd71636876adc13e065664
BLAKE2b-256 942a720c6ff93df413d2eca84e3e09bee0f8365cd84edc3a65558aab0f27ded1

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.4.0 This release

2 files

1.3.0

2 files

1.2.0

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page