Logging In

A coc.py client instance can be created directly by Client. The instance can then be logged in with the methods

async coc.Client.login(self, email: str, password: str) None

Retrieves all keys and creates an HTTP connection ready for use.

Parameters:
async coc.Client.login_with_tokens(self, *tokens: str) None

Creates an HTTP connection ready for use with the tokens you provide.

Parameters:

tokens (list[str]) – Tokens as found from https://developer.clashofclans.com under “My account” -> <your key> -> “token”.

Example

import coc
import asyncio

async def main():
    async with coc.Client(key_names="keys for my windows pc", key_count=5) as coc_client:
        await coc_client.login("email","password")
        # do stuff

if __name__ == "__main__":
    asyncio.run(main())
import coc
import asyncio

async def main():
    coc_client= coc.Client(key_names="keys for my windows pc", key_count=5)
    await coc_client.login("email","password")
    # do stuff
    await coc_client.close()

if __name__ == "__main__":
    asyncio.run(main())

With the logged in instance, you can complete any of the operations detailed below. The instance can be user either with a context manager or without as shown in the example.

Special Parameters

This details special parameters passed to the Client which may have more than 1 option (True/False). Currently this only includes LoadGameData, but may be expanded in the future.

LoadGameData

class coc.LoadGameData(**kwargs)

Pass this into the load_game_data parameter of Client.

See Game Data for more information.

Parameters:
  • always (bool) – Whether to always inject game metadata into objects.

  • default (bool) – Always inject game metadata into objects, except when running events tasks.

  • startup_only (bool) – Never automatically inject game metadata into objects, but load it up on startup regardless for use with the load_game_data parameter of Client.get_player() or Client.parse_army_link().

  • never (bool) – Never inject game metadata, and don’t load it on startup.