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. to retrieve your topstats.gg token, see https://docs.topstats.gg/authentication/tokens/
  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.1.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.1-py3-none-any.whl (13.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: topstats-1.0.1.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.1.tar.gz
Algorithm Hash digest
SHA256 0c07ddd2bbf40701b06d48ac6937c7e3a562ac0993b2f4cd20ccf04b6fa0f278
MD5 6471303687f6e5db4bbeb8d66d0ffff9
BLAKE2b-256 2e36db766d50d891a43573b32672b14bfd90c0d8c73f171e2929caaf83a4eb8c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: topstats-1.0.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8fe1918355af00c398f9d7ce9f39624adaae7f26f26f4a6458364dfc87fe9b66
MD5 aff31261419ba93d271b69761de4678f
BLAKE2b-256 7548d586ce5bd6bb4cb2c43bd42465f8b3162bfcd4b708b6f91d4d574b1c8e55

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