Skip to main content

Brawl stars API wrapper (sync + async + proxy + brawlapi)

Project description

Brawling 2.0

Sync + async wrapper for the Brawl Stars API (additionally via an unofficial proxy) and BrawlAPI by Brawlify

Installation

To install normally (only sync, no cache)

pip install brawling

There are three additional extras you can install: async, cache, acache

To install with caching support (only sync, installs requests-cache)

pip install brawling[cache]

To install with async support (will install aiohttp)

pip install brawling[async]

To install with async caching support (will also install aiohttp, aiohttp-client-cache and aiosqlite)

pip install brawling[acache]

Usage

Usage is fairly simple and straightforward:

import brawling

# either a token, or a path to the file with it
TOKEN = "..."

client = brawling.Client(TOKEN)
player = client.get_player("#YOURTAG")
print(f"Hi, {player.tag}")

# or, asynchronously

client = brawling.AsyncClient(TOKEN)
player = await client.get_player("#YOURTAG")
print(f"Hi, {player.tag}")

If you only need to make one or few calls, you can use a context manager:

with brawling.Client(TOKEN) as client:
    player = client.get_player("#YOURTAG")

# or, asynchronously
async with brawling.AsyncClient(TOKEN) as client:
    player = await client.get_player("#YOURTAG")

If you want to paginate over data, there are also paginator functions available to do exactly that:

pages = client.page_brawler_rankings(
    brawling.BrawlerID.SHELLY,
    per_page=10, region='us', max=200
)

# ^ this operation was immediate, no data was fetched yet

for page in pages:
    # prints a list of 10 items
    print(page)

# if asynchronous, use 'await client.page_xx()' and 'async for'

When initializing a client, there are additional options:

Client(token: str,
       proxy = False,
       strict_errors = True,
       cache = False)

proxy - uses the Royale API proxy (read Special thanks before using!) to make requests, useful if you don't have a static IP.

strict_errors - throw an error if the API returned one, if set to False, will return an ErrorResponse object instead.

cache - enables caching of responses, caching period is determined by either the API, or a fallback default value of 10 minutes.

Common issues

If you are having troubles with getting the AsyncClient to work, make sure that you initialize it inside an asynchronous function, like so:

client = None

# correct
async def init():
    client = brawling.AsyncClient("...")

asyncio.run(init())

# wrong
client = brawling.AsyncClient("...")

Special thanks

Thanks to brawlify for the amazing project BrawlAPI

Thanks to Royale API for providing a proxy service to bypass the static IP limitation

NOTE: These two tools were made by neither me nor Supercell. They have been included in this module just because of their convenience, I am not responsible for any use of them and cannot guarantee that they are, and will continue complying with Supercell's Terms of Service, and therefore it's not my fault if they turn out to be malicious in any way.

Disclaimer

This content is not affiliated with, endorsed, sponsored, or specifically approved by Supercell and Supercell is not responsible for it. For more information see Supercell’s Fan Content Policy: www.supercell.com/fan-content-policy.

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

brawling-2.0.2.tar.gz (17.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brawling-2.0.2-py3-none-any.whl (22.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: brawling-2.0.2.tar.gz
  • Upload date:
  • Size: 17.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.1 Windows/10

File hashes

Hashes for brawling-2.0.2.tar.gz
Algorithm Hash digest
SHA256 daeee54af7ad06f019819cae7ec2ca92f5a52b40cec1fc7e47ebe76ebc5770d8
MD5 5aa8a35e9a5166ea57e9209847ae793e
BLAKE2b-256 7392526349aebeb90dddb0f362fb66cd532e250a00172b18f6a91a744a592b38

See more details on using hashes here.

File details

Details for the file brawling-2.0.2-py3-none-any.whl.

File metadata

  • Download URL: brawling-2.0.2-py3-none-any.whl
  • Upload date:
  • Size: 22.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.0 CPython/3.11.1 Windows/10

File hashes

Hashes for brawling-2.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2924d6bf4db7992bb62b2202b2bba2fc2e0a2ac9537ceaee3f629c6cd126dc2d
MD5 98f8322fd3199cc3fafd01b1be2f8ffc
BLAKE2b-256 243df0cf3def2827bac0ceb6a6094b8f49f1454b45319d7258c0f2cfee25ade1

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