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.3.tar.gz (8.2 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.3-py3-none-any.whl (15.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: clash_of_clans_python_api-0.2.3.tar.gz
  • Upload date:
  • Size: 8.2 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.3.tar.gz
Algorithm Hash digest
SHA256 a1526a9253f64702af2df4b44f9d2d7e7fc8f9150cfc98fc67d892d954552316
MD5 6c9d09b8f72c864ae897cc72b8705213
BLAKE2b-256 afdb5de1c91b5f9f36f48f7a581ef9f304d6d976d1238b5d737e8b4a7a7c51a8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for clash_of_clans_python_api-0.2.3-py3-none-any.whl
Algorithm Hash digest
SHA256 0bf305adccb831214cdbdeb673ab169a72ee88b31ab481ec2a8d182075d2cc59
MD5 13263d23e7dada9d30eb73d4bf0647df
BLAKE2b-256 4b3ad93b20732c188f128fb5664970f07cef965acdee2ab4331ff84973731c0b

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