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.

GoldPassEndpoint

  • get(unix: bool = False) -> GoldPass

    Fetch start and endtime of the current goldpass season.

    • unix: If True returns start_time and end_time as unix timestampts instead of datime.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

clash_of_clans_python_api-0.2.4.tar.gz (9.1 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.4-py3-none-any.whl (16.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clash_of_clans_python_api-0.2.4.tar.gz
  • Upload date:
  • Size: 9.1 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.4.tar.gz
Algorithm Hash digest
SHA256 1ee69553e76e4150871e6e85513de413a78d2bddee4803ae62967386cd4a939b
MD5 acbac8cf948a263d8b076d28ee68c2bf
BLAKE2b-256 5ad87ed24b6fbc7a1abe6c237a27cd0f1bc1e47f31dd72a705492d144499b7c0

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for clash_of_clans_python_api-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 b087c0088e616ab551e8978112aeb94ea4718cd1c7b8b8181808fac230a0da0a
MD5 71cb3a0cf90d5ee534328a1c599be67f
BLAKE2b-256 cf69984bf6402607fc6f150ac6afaa6d24e53f0f15471b5d906bacb7cd9b5c27

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