Skip to main content

A wrapper for the official Clash of Clans API.

Project description

Clash of Clans Python API Wrapper

PyPI - Version

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.2.tar.gz (7.7 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.2-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clash_of_clans_python_api-0.2.2.tar.gz
  • Upload date:
  • Size: 7.7 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.2.tar.gz
Algorithm Hash digest
SHA256 9730c88de207d8040ddc9bfb03bdd39ffd3142e9ba9c88b97a7828c6426c5b29
MD5 f8d14f16b8345fbd5dd22a0a93da04f1
BLAKE2b-256 7a121d8c22dde285195f9d885b3247d6c639f5a87fd2e8d88d8804366afa02f6

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for clash_of_clans_python_api-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 eb5f987c6da7bf3bc53399510f07eae5f343f42450bf0fa9c4b90ccd28ab6e62
MD5 c2f097d90f4793d29e94af97c4147d67
BLAKE2b-256 cb5cbf7fcc273a7fc4602f8f162d2a6392d5c08e6507544680bb1db5ddc2bd7b

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