Skip to main content

A simple API wrapper for topstats.gg written in Python.

Project description

topstats pypi downloads

A simple API wrapper for topstats.gg written in Python.

Getting started

Make sure you already have an API token handy. See this page on how to retrieve it.

After that, run the following command in your terminal:

$ pip install topstats

Example

For more information, please read the documentation.

# Import the module.
import topstats

import asyncio
import os


async def main() -> None:
  
  # Declare the client.
  async with topstats.Client(os.getenv('TOPSTATS_TOKEN')) as ts:
    
    # Fetch a bot from its ID.
    bot = await ts.get_bot(432610292342587392)
    
    print(bot)

    # Fetch topstats.gg's top bots.
    bots = await ts.get_top_bots(sort_by=topstats.SortBy.server_count())
    
    for b in bots:
      print(b)
    
    # Search for bots that has the name 'MEE6.'
    mee6_bots = await ts.search_bots(name='MEE6')

    for b in mee6_bots:
      print(b)

    # Search for anime-tagged bots.
    anime_bots = await ts.search_bots(tag='anime')

    for b in anime_bots:
      print(b)
    
    # Fetch a bot's historical server count.
    sc = await ts.get_historical_bot_server_count(432610292342587392)

    for server_count in sc:
      print(server_count)
    
    # Compare two bots' historical server count.
    vs = await ts.compare_bot_server_count(432610292342587392, 437808476106784770)

    for first, second in vs:
      print(first, second)
    
    # Compare up to four bots' historical total vote count.
    vs2 = await ts.compare_bot_total_votes(
      topstats.Period.LAST_YEAR,
      339254240012664832,
      432610292342587392,
      408785106942164992,
      437808476106784770
    )

    for first, second, third, fourth in vs2:
      print(first, second, third, fourth)

if __name__ == '__main__':
  
  # See https://stackoverflow.com/questions/45600579/asyncio-event-loop-is-closed-when-getting-loop
  # for more details.
  if os.name == 'nt':
    asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
  
  asyncio.run(main())

Project details


Download files

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

Source Distribution

topstats-1.1.1.tar.gz (12.0 kB view details)

Uploaded Source

Built Distribution

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

topstats-1.1.1-py3-none-any.whl (16.2 kB view details)

Uploaded Python 3

File details

Details for the file topstats-1.1.1.tar.gz.

File metadata

  • Download URL: topstats-1.1.1.tar.gz
  • Upload date:
  • Size: 12.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for topstats-1.1.1.tar.gz
Algorithm Hash digest
SHA256 8bbf52c894581743ae7e780b06d8fae9595badd708368fe566486e5226a8a950
MD5 681d7c16bfdc2007931c9e348acb8b80
BLAKE2b-256 33491fe3e9f73fc622968627ccd9b320426211245e78c20f010513e609a0037e

See more details on using hashes here.

File details

Details for the file topstats-1.1.1-py3-none-any.whl.

File metadata

  • Download URL: topstats-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 16.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for topstats-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ccda2b330fc4e4aa749e968197024f8baac574eb03c0422260a39f985c877a5f
MD5 bf54df62e8562ab79c9f41cadbc07f69
BLAKE2b-256 e5377e1401073200a853472b172a0f30800e49dafbb19bc243fd6c565bf0764a

See more details on using hashes here.

Supported by

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