Skip to main content

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.

Metadata

Release files for clash-of-clans-python-api 0.2.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for clash-of-clans-python-api 0.2.5
File Size Uploaded Provenance Actions
clash_of_clans_python_api-0.2.5.tar.gz 9.2 kB Without provenance Details for clash_of_clans_python_api-0.2.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for clash-of-clans-python-api 0.2.5
File Interpreter ABI Platform Actions
clash_of_clans_python_api-0.2.5-py3-none-any.whl Python 3 none any Details for clash_of_clans_python_api-0.2.5-py3-none-any.whl

Total release size: 25.9 kB

Release files / clash_of_clans_python_api-0.2.5.tar.gz

Download URL clash_of_clans_python_api-0.2.5.tar.gz
Size 9.2 kB
Tags Source
SHA-256 checksum
How to use checksums
22d9ffd0dac299fc72eab3c264922389b10ad60b073ce1457116c98d1d4e3d7b
BLAKE2b-256 checksum
How to use checksums
10a68d5925ebd96e00a4c40a1f6e34872a609d3b7b6b7d2eeddcfb8752b9a3a5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.13.5 Windows/11

Release files / clash_of_clans_python_api-0.2.5-py3-none-any.whl

Download URL clash_of_clans_python_api-0.2.5-py3-none-any.whl
Size 16.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7eee3f53cdf2eb0e1a737805aed4ee271cfca6d7b33a38272a3a56e4087690e9
BLAKE2b-256 checksum
How to use checksums
6b31add3e8f40970f2e8e3feb313e15ab7b98a40309b2211f1158b2e150e3063
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/2.1.3 CPython/3.13.5 Windows/11

Security for clash-of-clans-python-api 0.2.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page