Skip to main content

The community-maintained Python API wrapper for topstats.gg.

Project description

topstats pypi downloads

The community-maintained Python API wrapper for topstats.gg.

Installation

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. the measuring unit used defaults to the metric system (celcius, km/h, etc.)
  async with topstats.Client('your topstats.gg API token') as ts:
    # fetch a ranked bot from its bot 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)
    
    # 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 votes
    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.0.0.tar.gz (9.8 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.0.0-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for topstats-1.0.0.tar.gz
Algorithm Hash digest
SHA256 a54e177a89d27f9e8285477eff025941e3eaa87d59aabe1ee05d3806e068533c
MD5 52f97cfe6607ac0c755f52c652317ca8
BLAKE2b-256 9fc66b78030429793e46d2ec24d4fee449c096856ea70e8506690b2d443a0cfe

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for topstats-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 356b6e2466067bf4f571afcdf0a0040082d0602980847e6bd751f0c7c72e527c
MD5 79ce9c909e9849355e661ede5a934dfc
BLAKE2b-256 9f0663eb23164ea36b4aede5d237a69539dbe89259c26a4ed25fa154f7341ebf

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