Skip to main content

An async Python API wrapper for the unofficial Brawl Stars API

Project description

PyPi Supported Versions 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 currently in the docs folder. If you see a mistake, open a pull request with the correct fix.

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.2.tar.gz (4.9 kB view details)

Uploaded Source

File details

Details for the file brawlstats-2.0.2.tar.gz.

File metadata

  • Download URL: brawlstats-2.0.2.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.12.1 pkginfo/1.4.2 requests/2.19.1 setuptools/40.6.2 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.0

File hashes

Hashes for brawlstats-2.0.2.tar.gz
Algorithm Hash digest
SHA256 c932bcd109072b5baf7fc92651ec00f739814b8d3078366d238033491f52f116
MD5 48dde6ef6d8ccbff87138cbd462ce7dd
BLAKE2b-256 d0a97b1d6526c057061f0576b211f360f34cc1d9b0236d1b2795166e5566a321

See more details on using hashes here.

Supported by

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