Miscellaneous

Graphics

Badge

class coc.Badge

Represents a Clash Of Clans Badge.

small

str - URL for a small sized badge (70x70).

medium

str - URL for a medium sized badge (200x200).

large

str - URL for a large sized badge (512x512).

url

str - Medium, the default URL badge size.

async save(filepath, size=None) int

Save this badge as a file-like object.

Parameters:
  • filepath (os.PathLike) – The filename to save the badge to.

  • size (Optional[str]) – Either small, medium or large. The default is medium.

Returns:

The number of bytes written

Return type:

int

Raises:

Icon

class coc.Icon

Represents a Clash Of Clans Icon.

tiny

str: URL for a tiny sized icon (32x32).

small

str: URL for a small sized icon (72x72).

medium

str: URL for a medium sized icon (288x288).

url

str: small, the default URL icon size

async save(filepath: str, size: Optional[str] = None) int

Save this icon as a file-like object.

Parameters:
  • filepath (os.PathLike) – The filename to save the badge to.

  • size (Optional[str]) – Either tiny, small or medium. The default is small.

Returns:

:class:`int`

Return type:

The number of bytes written.

Raises:

Time

Timestamp

class coc.Timestamp

Represents a Clash of Clans Timestamp

raw_time

str: The raw timestamp string (ISO8601) as given by the API.

property now: datetime

Returns the time of the timestamp as a datetime object in UTC.

Type:

datetime

property seconds_until: int

Returns the number of seconds until the timestamp. This may be negative.

Type:

int

property time: datetime

Returns the timestamp as a UTC datetime object.

Type:

datetime

TimeDelta

class coc.TimeDelta

Represents a Timedelta object corresponding to things that take time to do in the API.

Some examples include:

  • Upgrade times

  • Training times

  • Cooldown times

This object works in a very similar fashion to datetime’s timedelta object, but with a few more helpful attributes.

Note

You should not construct this yourself, instead use it from the attribute of an e.g. Troop model.

days

The number of days in the timedelta.

Type:

int

hours

The number of hours in the timedelta. This does not include days. For example, if an upgrade took 36 hours, the .days attribute would be 1, and .hours would be 12.

Type:

int

minutes

The number of minutes in the timedelta. The same logic applies as with hours.

Type:

int

seconds

The number of seconds in the timedelta. The same logic applies as with hours.

Type:

int

total_seconds()

Returns the total number of seconds in the time object.

This is the addition of all days, hours, minutes, seconds.

Returns:

The number of seconds

Return type:

int

Location

class coc.Location

Represents a Clash of Clans Location

id

int - The location ID

name

str - The location name

is_country

bool - Indicates whether the location is a country

country_code

str - The shorthand country code, if the location is a country

localised_name

str - A localised name of the location. The extent of the use of this is unknown at present.

Enumerations

The library provides some enumerations for certain types of strings, as well as orders for troops, spells and achievements that are used internally.

All Elixir Troops

ordered as they appear in-game.

coc.ELIXIR_TROOP_ORDER

All Dark Elixir Troops

ordered as they appear in-game.

coc.DARK_ELIXIR_TROOP_ORDER

All Siege Machines

ordered as they appear in-game.

coc.SIEGE_MACHINE_ORDER

All Super Troops

ordered as they appear in-game.

coc.SUPER_TROOP_ORDER

All Home Troops

ordered as they appear in-game.

This is a combination of elixir, dark elixir and siege machine troops. This does not contain super troops.

coc.HOME_TROOP_ORDER

All Builder Troops

ordered as they appear in-game.

coc.BUILDER_TROOPS_ORDER

All Elixir Spells

ordered as they appear in-game.

coc.ELIXIR_SPELL_ORDER

All Dark Elixir Spells

ordered as they appear in-game.

coc.DARK_ELIXIR_SPELL_ORDER

All Spells

ordered as they appear in-game.

coc.SPELL_ORDER

All Heroes

ordered as they appear in-game.

coc.HERO_ORDER

All Pets

ordered as they appear in-game.

coc.HERO_PETS_ORDER

All achievements

ordered as they appear in-game.

coc.ACHIEVEMENT_ORDER