Skip to main content

Brawl stars API wrapper (synchronous)

Project description

Brawling

Synchronous API wrapper for Brawl Stars made by Supercell

Installation

pip install brawling

To install with caching support (for performance, optional)

pip install brawling[cache]

Usage

Usage is very simple and straightforward:

import brawling

# This can be either the API token,
# or the path to the file with it.
TOKEN = "..."

# Initialize the client
client = brawling.Client(TOKEN)

battle_log = client.get_battle_log("#yourtag")

# Prints "Battle(battle_time=...)"
print(battle_log[0])

For some endpoints, there's also a possibility to page over them:

# Returns a generator which fetches up to 20 total pages
# of Ukrainian rankings for Shelly, each page
# being a list of BrawlerRanking model where 0 < len(page) <= 10
pages = client.page_brawler_rankings(
    brawling.BrawlerID.SHELLY,
    per_page=10, region='ua', max=200
)

# ^ Note that this operation was immediate,
# as no data is fetched yet.

# This will now fetch pages of 10 players,
# until either there are no players left,
# or we reach the max limit of 200.

# NOTE: Due to limitations of the API, page methods can return only return
# as many objects as get_* methods, so the only use for them is to
# minimize the traffic if you only need to retrieve a few objects.
for page in pages:
    print(page)

The client has additional options you can use when initializing:

Client(TOKEN, proxy=True, strict_errors=False, force_no_cache=True, force_no_sort=True)

With strict_errors set to False, the API methods can now silently fail instead of raising exceptions, and instead return an ErrorResponse object. It's your job to handle it.

The proxy argument will use a 3rd party proxy. Details on setting up are on the linked page. DISCLAIMER: I am not responsible for anything related to the proxy. I am not in any way related to its developers, and it's not my fault if your API access gets blocked because of using it.

force_no_cache will disable the caching of requests no matter what. This setting is useless if you didn't install with brawling[cache], and otherwise is only recommended if you're facing issues because of the cache (such as non-up-to-date responses)

By default, some methods that return a list will attempt to sort it. force_no_sort will disable that, and return everything in the exact order as it was received. Note that for now, only get_battle_log does any sorting, because the other methods already give out a sorted list. This is undocumented and may change at any time though, but I still decided that I won't add sorting to all the other methods, due to being a potentially useless performance decrease.

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

Uploaded Source

Built Distribution

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

brawling-1.0.0-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: brawling-1.0.0.tar.gz
  • Upload date:
  • Size: 12.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Windows/10

File hashes

Hashes for brawling-1.0.0.tar.gz
Algorithm Hash digest
SHA256 ac01a2590a0530e9a25ce930012b3ff185db0a1fd04ce016c072c67c3aa3585b
MD5 675817b45c65d6d0dc164826b82365e7
BLAKE2b-256 1ee0a0c1d1a5ea952a16e25fc42df4b2f63dfa947090e5c2edd887e8c5f964a7

See more details on using hashes here.

File details

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

File metadata

  • Download URL: brawling-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.1 CPython/3.10.4 Windows/10

File hashes

Hashes for brawling-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 d15c9cb3bf46c3c8c5669a98cc8a8b38f6fd82f78427fb058ad4b021958f26fc
MD5 ac904c4407406ed586821709d1e1889c
BLAKE2b-256 7f7c2d2cac7716eea61040f4b9f5c976ce7833e4e374270d2063a8a20b5ebd55

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