Skip to main content

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: If True, routes requests through RoyaleAPI's proxy.

Attributes:

  • players: Access player-related API endpoints.
  • clans: Access clan-related API endpoints.

PlayerEndpoints

  • get(player_tag: str) -> Player

    Fetch detailed information about a player.

  • verify_token(player_tag: str, token: str)

    Verify a player token with the API.

ClanEndpoints

  • get(clan_tag: str) -> Clan

    Fetch detailed information about a clan.

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

clash_of_clans_python_api-0.2.1.tar.gz (7.5 kB view details)

Uploaded Source

Built Distribution

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

clash_of_clans_python_api-0.2.1-py3-none-any.whl (13.6 kB view details)

Uploaded Python 3

File details

Details for the file clash_of_clans_python_api-0.2.1.tar.gz.

File metadata

  • Download URL: clash_of_clans_python_api-0.2.1.tar.gz
  • Upload date:
  • Size: 7.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.5 Windows/11

File hashes

Hashes for clash_of_clans_python_api-0.2.1.tar.gz
Algorithm Hash digest
SHA256 c448c4345a3c0a980b11d43a844f226c9a42058043083c679aefea6260f0b2f0
MD5 c0c1b3845afa20e016e5d1e476f51ef4
BLAKE2b-256 5e8559e24cab7a8b6894a18e3aaa2003189eaa6668b29f458c271e10617e2690

See more details on using hashes here.

File details

Details for the file clash_of_clans_python_api-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for clash_of_clans_python_api-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 cbe249e1c051e40e7e624c05a4e615db1a3b8d71470e61479e67f6763406943b
MD5 45226fdee3f3c71d358f4ffd950d308a
BLAKE2b-256 e7fc443e72dc8ce286e8c6a66f0e4f5339300237db24c6216b59a819a5174d05

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