Skip to main content

Async client for the DonutSMP API

Project description

donutstats

Async Python wrapper for the DonutSMP API.

PyPI Python License

tests

Install

Basic Install

pip install donutstats

Discord Feature Usage

pip install donutstats[discord]

Usage

Simple api usage

import asyncio
from donutstats import DonutStats

async def main():
    donutstats = DonutStats("Your DonutSMP api key (generate ingame with /api")

    # Full stats dict
    stats = await donutstats.get_stats(username="copa6076") # Pull the stats from donutsmp api
    print(stats.get('money')) # 2920840615

    # Single stat
    shards = await donutstats.get_shards(username="copa6076") # Pull the shards from donutsmp api
    print(shards) # 8410

    await donutstats.close() # Close it when you close your bot

asyncio.run(main())

Simple discord bot cog usage

import discord
from discord.ext import commands

from donutstats import DonutStats

class Stats(commands.Cog):
    def __init__(self, bot: commands.Bot):
        # Initialize donutstats when your cog gets initialized
        self.donutstats = DonutStats("Your DonutSMP api key (generate ingame with /api")

    @discord.app_commands.command()
    async def stats(self, interaction: discord.Interaction, username: str):
        # Returns a full stats embed
        embed: discord.Embed = await self.donutstats.get_stats_embed(username, discord.Color.blue())

        await interaction.response.send_message(embed=embed)

async def setup(bot: commands.Bot):
    await bot.add_cog(Stats(bot))

Exceptions

  • DonutSMPError - Raised when DonutSMP cannot handle a query, Very likely could not find username
  • UnauthorizedRequest - Raised when DonutSMP returns a 401 unauthorized.
  • RateLimited - Raised when DonutSMP returns a 429 ratelimited
  • UnexpectedError - Raised when there is an unexpected api response status.

License

MIT License LICENSE

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

donutstats-1.1.1.tar.gz (7.4 kB view details)

Uploaded Source

Built Distribution

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

donutstats-1.1.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: donutstats-1.1.1.tar.gz
  • Upload date:
  • Size: 7.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for donutstats-1.1.1.tar.gz
Algorithm Hash digest
SHA256 500617fa3044d94897ff24298f2002d159f0042b6ff97373931c9af9325018f4
MD5 5129bb929a027a17984cb039561d99d2
BLAKE2b-256 cd2c347a6dde86208e947d2dffe0391f93f09d90cb9a16b3ca38a4cac3ece1da

See more details on using hashes here.

File details

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

File metadata

  • Download URL: donutstats-1.1.1-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for donutstats-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 611b1bb2dd5096bb593f4f8d959232c3c93604dad2fa18dea30a3d9c8df59a18
MD5 f44c06f0bdb4eb3689de5011f19d7d46
BLAKE2b-256 2240ea8504f47672f11ebe3ce8ad6a00ab97812477d351bc0c53ee0bf1ec3235

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