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.2.tar.gz (7.5 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.2-py3-none-any.whl (6.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: donutstats-1.1.2.tar.gz
  • Upload date:
  • Size: 7.5 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.2.tar.gz
Algorithm Hash digest
SHA256 8702dd372d7f93e111da70893a0c6d72c03dc1d8a217eba4fef655579a56c0a7
MD5 3fdbfa7190beda2589df38ea3bd31db3
BLAKE2b-256 884836d23541f9263dc5f3923dec9c8366a41902de27cd45c1e590efb46a7379

See more details on using hashes here.

File details

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

File metadata

  • Download URL: donutstats-1.1.2-py3-none-any.whl
  • Upload date:
  • Size: 6.7 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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 a8204270d443044bb32f89f082c375ee7bd2e02b309a01a9950bc7175ce3f907
MD5 668191b944c0a55fe65c001e141176d2
BLAKE2b-256 209a1bd521aa8f2d175ee99799df8fbdf91b5674dc3085d14980e2ac1b18a24c

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