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 -i https://test.pypi.org/simple/ clash-of-clans-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.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-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.tar.gz.

File metadata

  • Download URL: clash_of_clans_python_api-0.2.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.tar.gz
Algorithm Hash digest
SHA256 8fd2b1d2214782aeb5797e6a6a422506852bf9306af7535965dce37c0ebb29e6
MD5 e17b3e675d2c65f32cff7b97ef5a140c
BLAKE2b-256 48be7f0311903a14b722fa62a24728ec3139acfe7382b09b88675d4030fbf44b

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for clash_of_clans_python_api-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 309049b532b15677d5ab6ebb5608460ffa75943a6ed782afb435074039c80b42
MD5 a6a069b21c5c034c19b04b98b91f5960
BLAKE2b-256 779e308263fdabe757c6c8fef8830a11366343eb9d5f52446990dd683d35c2a9

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