Skip to main content

A python wrapper for the Clash of Clans API

Project description

clashy.py

Discord Server Invite PyPI version info PyPI supported Python versions

Easy to use asynchronous Clash of Clans API wrapper in Python.

Key Features

  • Asynchronous code

  • Entire coverage of the official Clash of Clans API

  • Email/password login removes the stress of managing tokens

  • Optimised for speed, memory and performance

Getting Started

Installing

Python 3.10 or higher is required

# UV (recommended)
uv add clashy.py

# Linux/macOS
python3 -m pip install -U clashy.py

# Windows
py -3 -m pip install -U clashy.py}

# to install the development version:
python3 -m pip install -U git+https://github.com/ClashKingInc/clashy.py

Quick Example

This is the basic usage of the library. This example will get a player with a certain tag, and search for 5 clans with a name.

import asyncio
import coc


async def main():
    async with coc.Client() as coc_client:
        try:
            await coc_client.login("email", "password")
        except coc.InvalidCredentials as error:
            exit(error)

        player = await coc_client.get_player("tag")
        print(f"{player.name} has {player.trophies} trophies!")

        clans = await coc_client.search_clans(name="best clan ever", limit=5)
        for clan in clans:
            print(f"{clan.name} ({clan.tag}) has {clan.member_count} members")

        try:
            war = await coc_client.get_current_war("#clantag")
            print(f"{war.clan_tag} is currently in {war.state} state.")
        except coc.privatewarlog:
            print("uh oh, they have a private war log!")

if __name__ == "__main__":
    try:
        asyncio.run(main())
    except KeyboardInterrupt:
        pass

Basic Events Example

This script will run forever, printing to the terminal whenever someone joins the clan or a member of the clan donates troops.

import asyncio
import logging

import coc


@coc.ClanEvents.member_join()
async def foo(player, clan):
    print(f"{player.name} ({player.tag}) just joined {clan.name} ({clan.tag})")


@coc.ClanEvents.member_donations()
async def bar(old_member, member):
    troops_donated = member.donations - old_member.donations
    print(f"{member.name} just donated {troops_donated} troops!")


async def main():
    coc_client = coc.EVentsClient()
    try:
        await coc.login("email", "password")
    except coc.InvalidCredentials as error:
        exit(error)

    # Register all the clans you want to monitor
    list_of_clan_tags = ["tag1", "tag2", "tag3"]
    coc_client.add_clan_updates(*list_of_clan_tags)

    # Register the callbacks for each of the events you are monitoring
    coc_client.add_events(
        foo,
        bar
    )


if __name__ == "__main__":
    logging.basicConfig(level=logging.INFO)
    log = logging.getLogger()

    loop = asyncio.get_event_loop()
    try:
        loop.run_until_complete(main())
        loop.run_forever()
    except KeyboardInterrupt:
        pass

For more examples see the examples directory

Contributing

Contributing is fantastic and much welcomed! If you have an issue, feel free to open an issue and start working on it.

If you wish to run, setup or work on documentation, you will need to install sphinx and a few related dependencies. These can be installed with:

pip install -r doc_requirements.txt
cd docs
make html

If you wish to run linting, pylint, black and flake8 have been setup and can be run with:

python setup.py lint

Disclaimer

This content is not affiliated with, endorsed, sponsored, or specifically approved by Supercell and Supercell is not responsible for it. For more information see Supercell’s Fan Content Policy.

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

clashy_py-26.4.1.tar.gz (1.2 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

clashy_py-26.4.1-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file clashy_py-26.4.1.tar.gz.

File metadata

  • Download URL: clashy_py-26.4.1.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clashy_py-26.4.1.tar.gz
Algorithm Hash digest
SHA256 4871f749db5b8d0128349e518ad13d410876b78dc88beb9bd821b99eae695f54
MD5 9eeacb83e523a12baa4c095730ab4633
BLAKE2b-256 c9741b9699f6a0599f06246828d77d250377f5d44f9480c6bcd475d536120698

See more details on using hashes here.

Provenance

The following attestation bundles were made for clashy_py-26.4.1.tar.gz:

Publisher: push-to-pypi.yml on ClashKingInc/clashy.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file clashy_py-26.4.1-py3-none-any.whl.

File metadata

  • Download URL: clashy_py-26.4.1-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for clashy_py-26.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 bfd1a519637a9dcb3608967b0a37127498a922913c863e05bab016e061dc09c5
MD5 96b6ac7555a1a32b9dcfcb233dce5df6
BLAKE2b-256 0b42acd5e67a0f1c53a6dd5b910c3f71c8b8582c0c09a145e020d0a731aec98a

See more details on using hashes here.

Provenance

The following attestation bundles were made for clashy_py-26.4.1-py3-none-any.whl:

Publisher: push-to-pypi.yml on ClashKingInc/clashy.py

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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