Quickstart#

This page gives a brief introduction to the module. It assumes you have the module already installed, if you don’t check the Installing portion. You can find examples here.

You can switch between the tutorial for the synchronous client and the asynchronous client with the tabs.

About the asynchronous client#

Note

If you’re new to Python or you don’t need to use the asynchronous client, you can probably skip this section.

The asynchronous client has the same methods as the synchronous client, but all of them are coroutines. That means that you can use methods like Client.login(), but you need to do await client.login(...) instead of client.login(...).

It works like this for methods of CodinGame models, like CodinGamer.get_followers() needs to be awaited with the asynchronous client.

Get a CodinGamer#

Getting a CodinGamer from their pseudo with the Client.get_codingamer() method:

import codingame

client = codingame.Client()

codingamer = client.get_codingamer("pseudo")
print(codingamer)
print(codingamer.pseudo)
print(codingamer.public_handle)
print(codingamer.avatar_url)
import codingame
import asyncio

async def main():
    client = codingame.Client(is_async=True)

    codingamer = await client.get_codingamer("pseudo")
    print(codingamer)
    print(codingamer.pseudo)
    print(codingamer.public_handle)
    print(codingamer.avatar_url)

asyncio.run(main())

Note

You can also use a public handle (39 character long hexadecimal string at the end of its profile link) or a user ID. Just replace the "pseudo" with the public handle or user ID.

See also

See Client.get_codingamer() and CodinGamer for more info.

Get a Clash of Code#

Getting a Clash of Code from its public handle with the Client.get_clash_of_code() method or the next public clash with Client.get_pending_clash_of_code():

import codingame

client = codingame.Client()

# get a clash of code from its handle
coc = client.get_clash_of_code("handle")
# or get the next public clash
coc = client.get_pending_clash_of_code()

print(coc)
print(coc.join_url)
print(coc.modes)
print(coc.programming_languages)
print(coc.public_handle)
print(coc.players)
import codingame
import asyncio

async def main():
    client = codingame.Client(is_async=True)

    # get a clash of code from its handle
    coc = await client.get_clash_of_code("handle")
    # or get the next public clash
    coc = await client.get_pending_clash_of_code()

    print(coc)
    print(coc.join_url)
    print(coc.modes)
    print(coc.programming_languages)
    print(coc.public_handle)
    print(coc.players)

asyncio.run(main())

Note

The public handle is the 39 character long hexadecimal string at the end of the Clash of Code invite link.

Login#

As of 2021-10-27, logging in with the email and the password no longer works because of an endpoint change, see issue #5. The only way to fix it is to log in with cookie authentication, you need to get the rememberMe cookie from CodinGame. This cookie should be valid for 1 year, but you might need to update it every time you log in on CodinGame.

  1. Open https://codingame.com.

  2. Log into your account, if you’re not logged in already.

  3. Access and copy the rememberMe cookie:

    Open the developer console (F12), go to the Application tab, look for the rememberMe cookie then copy its value.

    Screenshot of where to find the cookie in Chrome

    Open the developer console (F12), go to the Storage tab, look for the rememberMe cookie then copy its value.

    Screenshot of where to find the cookie in Firefox
  1. Paste the rememberMe cookie in the code below:

import codingame

client = codingame.Client()
client.login(remember_me_cookie="your cookie here")

# then you can access the logged in codingamer like this
print(client.logged_in)
print(client.codingamer)
print(client.codingamer.pseudo)
print(client.codingamer.public_handle)
print(client.codingamer.avatar_url)
import codingame
import asyncio

async def main():
    client = codingame.Client(is_async=True)
    await client.login(remember_me_cookie="your cookie here")

    # then you can access the logged in codingamer like this
    print(client.logged_in)
    print(client.codingamer)
    print(client.codingamer.pseudo)
    print(client.codingamer.public_handle)
    print(client.codingamer.avatar_url)

asyncio.run(main())

See also

See Client and Client.login() for more info.

Note

Don’t worry, the cookie isn’t saved nor shared.

Once you are logged in, you have access to many more methods of the Client, like Client.get_unseen_notifications(), and of the logged in CodinGamer, like CodinGamer.get_followers().

Get unseen notifications#

Getting a list of the unseen notifications of the logged in CodinGamer with the Client.get_unseen_notifications() method:

import codingame

client = codingame.Client()
client.login("email", "password")

notifications = list(client.get_unseen_notifications())

print(f"{len(notifications)} unseen notifications:")
for notification in notifications:
    print(notification.type_group, notification.type)
import codingame
import asyncio

async def main():
    client = codingame.Client(is_async=True)
    await client.login("email", "password")

    notifications = []
    async for notification in client.get_unseen_notifications():
        notifications.append(notification)

    print(f"{len(notifications)} unseen notifications:")
    for notification in notifications:
        print(notification.type_group, notification.type)

asyncio.run(main())

See also

See Client.get_unseen_notifications() and Notification for more info.