An async Python API wrapper for the unofficial Brawl Stars API
Project description
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
Release history Release notifications | RSS feed
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 details)
File details
Details for the file brawlstats-2.0.5.tar.gz
.
File metadata
- Download URL: brawlstats-2.0.5.tar.gz
- Upload date:
- Size: 4.7 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | d6bb11a369680b6481d2026070c630118d81bd3b47380d5e05a82f8b6faa53e8 |
|
MD5 | 0a1a1163ab855cc7350137636cbd02fa |
|
BLAKE2b-256 | 2bd1f0b5a0e9a9d257e787a105fba3aa334b002b152ad0e885cb1dd008bf4ebe |