Skip to main content

A sync Python 3.6+ wrapper for RoyaleAPI.

Project description

clashroyaleapi v0.2.1

A sync Python 3.6+ wrapper for RoyaleAPI. (WIP)

This wrapper's code style is inspired by python-telegram-bot, Telethon and Jeff's crpy. This wrapper attempts to provide an alternative which uses dataclasses to the existing Python wrappers for RoyaleAPI.

You are recommended to read RoyaleAPI's documentation before using this wrapper as the documentation for this wrapper is to be written. You may also reference the short examples below.

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.


This project is on PyPI.

pip install clashroyaleapi

Obtaining Developer Key

Follow these instructions to obtain your developer key.

Currently Supported Methods

Methods with an alias indicate that multiple tags can be passed to them.

client.get_player()          # alias: client.get_players()
client.get_player_chests()   # alias: client.get_players_chests()
client.get_player_battles()  # alias: client.get_players_battles()
client.get_clan()            # alias: client.get_clans()
client.get_clan_tracking()   # alias: client.get_clans_tracking()
client.track_clan()          # alias: client.track_clans()
client.get_tournament()      # alias: client.get_tournaments()

Lists, tuples, dicts, sets and generators can be used when passing arguments to methods accepting multiple tags. All of the following method calls are valid and return the same result.

p = [tag1, tag2, tag3]

client.get_players(tag for tag in p)   # If you want to do this somehow

Short examples of using the wrapper

Player/Clan/Tournament tags will be "corrected" and validated before requesting the API.

Example 1: with statement

import royaleapi

with royaleapi.RoyaleAPIClient("YOUR_DEVELOPER_KEY") as client:
    p = client.get_player("2RQJ0OYYC", timeout=100)
    print(,, p.deck[0].name, sep=", ")
    c1, c2 = client.get_clans("c9c8pcp", "#8LYRRV2")
    print(c1.badge == c2.badge, c1.location == c2.location, sep=", ")
    print([(, c.members[0].name, c.members[0].trophies) for c in (c1, c2)])

# My results:
# Trainer Jono, Golem, The Log
# False, True
# [('新香港部落123', '花果山劉德華', 5073), ('香港部落·二部', 'Gnuelnam', 4479)]

(2nd clan does not exist anymore, you will get an error trying this.)

Example 2: Using cached data

import time
from royaleapi import RoyaleAPIClient

client = RoyaleAPIClient("YOUR_DEVELOPER_KEY", use_cache=True)
player_tag = "9YJ2RR8G"
t1 = time.time()
p1 = client.get_player(player_tag)
t2 = time.time()
p2 = client.get_player(player_tag)
t3 = time.time()
p3 = client.get_player(player_tag, use_cache=False)
t4 = time.time()
print(t2 - t1, t3 - t2, t4 - t3, p1 == p2 == p3, sep=", ")

# My results
# 2.3867766857147217, 0.28074216842651367, 1.4506447315216064, True

# The first call takes the longest time since the data is not cached locally or on RoyaleAPI's server.
# The second call takes the shortest time since the data is cached locally.
# The third call takes less time than the first call since the data is cached on RoyaleAPI's server.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for clashroyaleapi, version 0.2.1
Filename, size File type Python version Upload date Hashes
Filename, size clashroyaleapi-0.2.1-py3-none-any.whl (44.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size clashroyaleapi-0.2.1.tar.gz (26.7 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page