A wrapper for the official Clash of Clans API.
Project description
Clash of Clans Python API Wrapper
An (in development) asynchronous Python wrapper for the official Clash of Clans API.
This library simplifies accessing player and clan data, handling authentication, HTTP requests, and response parsing.
Installation
pip install clash-of-clans-python-api
Usage Example
import asyncio
import os
from coc_api import ClashOfClansAPI
from coc_api.models import Player
API_TOKEN = os.getenv("API_TOKEN")
PLAYER_TAG = "#L8PRCJVL2"
async def main() -> None:
"""
Example usage of the ClashOfClansAPI to fetch and print player data.
"""
if not API_TOKEN:
raise ValueError("API_TOKEN environment variable is not set.")
api = ClashOfClansAPI(token=API_TOKEN, proxy=True)
try:
# Fetch player data
player: Player = await api.players.get(PLAYER_TAG)
print("Player Info:")
print(f"Name: {player.name}")
print(f"Town Hall Level: {player.town_hall_level}")
print(f"Clan: {player.clan.name if player.clan else 'No clan'}")
except Exception as e:
print("An error occurred while fetching player data:")
print(repr(e))
finally:
await api.close()
if __name__ == "__main__":
asyncio.run(main())
API Overview
ClashOfClansAPI(token: str, timeout: int = 10, proxy: bool = False)
Main client class to interact with the Clash of Clans API.
token: Your Clash of Clans API token.timeout: Request timeout in seconds (default: 10).proxy: IfTrue, routes requests through RoyaleAPI's proxy.
Attributes:
players: Access player-related API endpoints.clans: Access clan-related API endpoints.
PlayerEndpoints
-
get(player_tag: str) -> PlayerFetch detailed information about a player.
-
verify_token(player_tag: str, token: str)Verify a player token with the API.
ClanEndpoints
-
get(clan_tag: str) -> ClanFetch detailed information about a clan.
GoldPassEndpoint
-
get(unix: bool = False) -> GoldPassFetch start and endtime of the current goldpass season.
unix: IfTruereturns start_time and end_time as unix timestampts instead ofdatime.datime. Defaults to False.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file clash_of_clans_python_api-0.2.5.tar.gz.
File metadata
- Download URL: clash_of_clans_python_api-0.2.5.tar.gz
- Upload date:
- Size: 9.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
22d9ffd0dac299fc72eab3c264922389b10ad60b073ce1457116c98d1d4e3d7b
|
|
| MD5 |
3d3ec950a93a58d38fb22ba0bc2f3789
|
|
| BLAKE2b-256 |
10a68d5925ebd96e00a4c40a1f6e34872a609d3b7b6b7d2eeddcfb8752b9a3a5
|
File details
Details for the file clash_of_clans_python_api-0.2.5-py3-none-any.whl.
File metadata
- Download URL: clash_of_clans_python_api-0.2.5-py3-none-any.whl
- Upload date:
- Size: 16.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/2.1.3 CPython/3.13.5 Windows/11
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7eee3f53cdf2eb0e1a737805aed4ee271cfca6d7b33a38272a3a56e4087690e9
|
|
| MD5 |
5efc90aaf00cffbd8b8cda7d5e0f795b
|
|
| BLAKE2b-256 |
6b31add3e8f40970f2e8e3feb313e15ab7b98a40309b2211f1158b2e150e3063
|