Skip to main content

An async Python API wrapper for the unofficial Brawl Stars API

Project description

PyPi MIT License

This library is an async wrapper Brawl Stars API

Installation

Install the latest stable build:

pip install brawlstats

Install the development build:

pip install git+https://github.com/SharpBit/brawlstats

Documentation

Documentation is being hosted on Read the Docs

Misc

If you come across an issue in the wrapper, please create an issue and I will look into it ASAP. If you need help or an API Key, join the API’s discord server.

Examples

Using an async loop.

import brawlstats
import asyncio

loop = asyncio.get_event_loop() # do this if you don't want to get a bunch of warnings
client = brawlstats.Client('token', loop=loop)
# Do not post your token on a public github

# await only works in an async loop
async def main():
    player = await client.get_profile('GGJVJLU2')
    print(player.trophies) # access attributes using dot notation.
    print(player.solo_showdown_victories) # access using snake_case instead of camelCase
    band = await player.get_band(full=True) # full gets the full Band object
    print(band.tag)
    best_players = band.members[0:3] # members sorted by trophies, gets best 3 players
    for player in best_players:
        print(player.name, player.trophies) # prints name and trophies
    # NOTE: this is currently not working.
    leaderboard = await client.get_leaderboard('players', 5) # gets top 5 players
    for player in leaderboard:
        print(player.name, player.position)

# run the async loop
loop.run_until_complete(main())

Discord Bot Cog (discord.py v1.0.0a rewrite)

import discord
from discord.ext import commands
import brawlstats # import the module

class BrawlStars:
    """A simple cog for Brawl Stars commands"""

    def __init__(self, bot):
        self.bot = bot
        self.client = brawlstats.Client('token', loop=bot.loop) # Initiliaze the client using the bot loop

    @commands.command()
    async def profile(self, ctx, tag):
        """Get a brawl stars profile"""
        try:
            player = await self.client.get_profile(tag)
        except brawlstats.RequestError as e: # catches all exceptions
            return await ctx.send('```\n' + str(e.code) + ': ' + e.error + '\n```') # sends code and error message
        await ctx.send('Name: {0.name}\nTrophies: {0.trophies}'.format(player)) # sends player name and trophies


def setup(bot):
    bot.add_cog(BrawlStars(bot))

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

brawlstats-2.0.5.tar.gz (4.7 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page