Migrating to coc.py v2.0

Most of the outward facing library is the same, with a few changes detailed below. One significant change is the introduction of game data into Troop, Spell, Hero and Pet objects. You can read more about that here: Game Data.

Logging in with keys

A popular request was made to be able to use the client without the automatic key management. You can now initiate coc.py with a list of keys (or tokens), using the coc.login_with_keys() method.

Additional methods / attributes for models

A popular feature request was to be able to know “is this troop the max for the player’s TH level”. Before, this would require you to keep a static list of troop levels and do a lookup. This has been integrated into coc.py, and many models have this attribute now:

Similarly, you can use Troop.get_max_level_for_townhall to do the opposite - get the max troop level for a specific townhall. More on that in the Game Data section, however.

  • WarClan.average_attack_duration is now a valid property, thanks to doluk for implementing this.

  • Player.war_opted_in was added, to reflect the September update in the API.

  • ClanWar.attacks_per_member was added, which details the number of attacks each member has in the war, also in the September update.

  • Player.clan_previous_rank was fixed, it didn’t point to the correct API field before.

Miscellaneous

  • ujson has been added to the requirements and will be used where possible, as a faster method of deserialising json payloads from the API.

  • Internal handling of keys has been written to make it more stable.

  • Flame Flinger, Super Bowler and Super Dragon were all added to coc.py.