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-0.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-0.1.1-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: donutstats-0.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-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d8d41791f27cbe9e8d982bf415cb0a0e5c6130da393abacaa576010625c7670f
MD5 96117a65c9d3672c283a64f9e2874603
BLAKE2b-256 781b885a022f4893ff25a1329e3650a28f3f7c2b01a7934941dd8813970a25b0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: donutstats-0.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-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a12714d14fc099422a5e5c8b4eff991a2c16f4d59a2cf7e666c2ed15f26c441f
MD5 6fc697a499cf6cb99a50155bb1cc4f06
BLAKE2b-256 409428e338f05f912b539e02be6b1ff5fbbb40407feedcbe37ec2c4ddcb30391

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