codingame 1.5.0 API Reference#
The following section outlines the API of the codingame
module. All the
public classes, methods and functions are documented here.
Client#
Hybrid client#
- class codingame.Client(is_async=False)[source]#
Client for the CodinGame API.
Instanciates a
SyncClient
ifis_async
isFalse
or not given. Instanciates aAsyncClient
ifis_async
isTrue
.Note
There are docs for both
SyncClient
andAsyncClient
.- Parameters:
is_async (bool) – Whether the client is asynchronous. Defaults to
False
.
- property codingamer#
The CodinGamer that is logged in.
None
if the client isn’t logged in.- Type:
Optional
CodinGamer
- abstract create_private_clash_of_code(language_ids=[], modes=[])#
This function can be a coroutine.
Create a private
Clash of Code
with specified programming languages and modes.You need to be logged in to create a Clash of Code or else a
LoginRequired
will be raised.Note
If an invalid language is given, the API will ignores that language instead of raising an error. This function acts the same way.
- Parameters:
language_ids (
list
ofstr
) – The programming languages allowed in the Clash of Code. Get the list of options withget_language_ids()
. Default: All languages allowed.modes (
list
ofstr
) – The modes from which the Clash of Code mode is chosen from. The valid modes are SHORTEST, FASTEST and REVERSE. Default: All modes allowed.
- Raises:
ValueError – The modes are invalid.
LoginRequired – The Client needs to log in. See
login()
.
- Returns:
ClashOfCode
The created Clash Of Code.
.. versionadded:: 1.5
- abstract get_challenge_leaderboard(challenge_id, group='global')#
This function can be a coroutine.
Get the
leaderboard of a challenge
.You can specify an optional group of users to rank.
- Parameters:
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.ChallengeNotFound – There is no challenge with the given
challenge_id
.
- Returns:
ChallengeLeaderboard
The leaderboard of the requested challenge.
.. versionadded:: 0.4
- abstract get_clash_of_code(handle)#
This function can be a coroutine.
Get a
Clash of Code
from its public handle.- Parameters:
handle (
str
) – The Clash of Code’s public handle. 39 character long hexadecimal string (regex:[0-9]{7}[0-9a-f]{32}
).- Raises:
ValueError – The Clash of Code handle isn’t in the good format.
ClashOfCodeNotFound – The Clash of Code with the given public handle isn’t found.
- Returns:
ClashOfCode
The requested Clash Of Code.
.. versionadded:: 0.2
- abstract get_codingamer(codingamer)#
This function can be a coroutine.
Get a
CodinGamer
from their public handle, their ID or from their pseudo.Note
codingamer
can be the public handle, the ID or the pseudo. Using the public handle or the ID is reccomended because it won’t change even if the codingamer changes their pseudo.The public handle is a 39 character long hexadecimal string that is unique to the CodinGamer and identifies them. Regex of a public handle:
[0-9a-f]{32}[0-9]{7}
The ID is a 7 number long integer.
- Parameters:
codingamer (
str
orint
) – The CodinGamer’s public handle, ID or pseudo.- Raises:
CodinGamerNotFound – The CodinGamer with the given public handle, ID or pseudo isn’t found.
- Returns:
CodinGamer
The requested CodinGamer.
.. versionadded:: 0.1
.. versionchanged:: 0.2 – Renamed
Client.codingamer()
toget_codingamer()
... versionchanged:: 0.3.3 – Add searching with CodinGamer pseudo.
.. versionchanged:: 0.3.5 – Add searching with CodinGamer ID.
- abstract get_global_leaderboard(page=1, type='GENERAL', group='global')#
This function can be a coroutine.
Get the
global leaderboard
of CodinGame.You can specify an optional page, type of leaderboard and the group of users to rank.
- Parameters:
page (Optional
int
) – The page of the leaderboard to get the users from. Default:1
.type (Optional
str
) – The type of global leaderboard to show. One of"GENERAL"
,"CONTESTS"
,"BOT_PROGRAMMING"
,"OPTIM"
or"CODEGOLF"
. Default:"GENERAL"
.group (Optional
str
) – The group of users to rank. For every group except"global"
, you need to be logged in. One of"global"
,"country"
,"company"
,"school"
or"following"
. Default:"global"
.
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.
- Returns:
GlobalLeaderboard
The global leaderboard of CodinGame.
.. versionadded:: 0.4
- abstract get_language_ids()#
This function can be a coroutine.
Get the list of all available language IDs.
- Returns:
.. versionadded:: 0.3
.. versionchanged:: 1.0 – Renamed
Client.language_ids
toget_language_ids()
.
- abstract get_pending_clash_of_code()#
This function can be a coroutine.
Get the pending public
Clash of Code
.- Returns:
- Optional
ClashOfCode
The pending Clash Of Code if there’s one, or
None
if there’s no current public Clash Of Code.
- Optional
.. versionadded:: 0.3.2
- abstract get_puzzle_leaderboard(puzzle_id, group='global')#
This function can be a coroutine.
Get the
leaderboard of a puzzle
.You can specify an optional group of users to rank.
- Parameters:
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.PuzzleNotFound – There is no puzzle with the given
puzzle_id
.
- Returns:
PuzzleLeaderboard
The leaderboard of the requested puzzle.
.. versionadded:: 0.4
- abstract get_read_notifications()#
This function can be a coroutine.
Get the read
notifications
of the logged inCodinGamer
.You need to be logged in to get notifications or else a
LoginRequired
will be raised.Warning
There can be some old notifications missing.
Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– A read notification.
New in version 1.3.
- abstract get_unread_notifications()#
This function can be a coroutine.
Get all the unread
notifications
of the logged inCodinGamer
.This includes unseen notifications along with the unread ones.
You need to be logged in to get notifications or else a
LoginRequired
will be raised.Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– An unread notification.
New in version 1.3.
- abstract get_unseen_notifications()#
This function can be a coroutine.
Get all the unseen
notifications
of the logged inCodinGamer
.You need to be logged in to get notifications or else a
LoginRequired
will be raised.Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– An unseen notification.
New in version 0.3.1.
Changed in version 1.0: Renamed
Client.notifications
toget_unseen_notifications()
.
- abstract join_private_clash_of_code(handle)#
This function can be a coroutine.
Join the private
Clash of Code
with the specified handle.You need to be logged in to join a Clash of Code or else a
LoginRequired
will be raised.- Parameters:
handle (
ClashOfCode
orstr
) – The Clash of Code to join or its public handle.- Raises:
ValueError – The Clash of Code handle isn’t in the good format.
LoginRequired – The Client needs to log in. See
login()
.ClashOfCodeFinished – The Clash of Code is already finished.
- Returns:
ClashOfCode
The joined Clash Of Code.
.. versionadded:: 1.5
- abstract login(email=None, password=None, remember_me_cookie=None)#
This function can be a coroutine.
Login to a CodinGame account.
Error
As of 2021-10-27, the only way to login is with cookie authentication, so with the
remember_me_cookie
parameter, because of an endpoint change, see Login. Using email/password authentication will raise aLoginError
.- Parameters:
email (Optional
str
) – Email adress of the CodinGamer. Not needed if using session ID login.password (Optional
str
) – Password of the CodinGamer. Not needed if using cookie login.remember_me_cookie (Optional
str
) –rememberMe
cookie from CodinGame cookies. Not needed if using email/password login.
- Raises:
LoginError – Error with the login (empty email, empty password, wrong email format, incorrect password, etc).
- Returns:
CodinGamer
The CodinGamer that logged in.
.. versionadded:: 0.3
- abstract mark_notifications_as_read(notifications)#
This function can be a coroutine.
Mark
notifications
of the logged inCodinGamer
as read.You need to be logged in to mark notifications as read or else a
LoginRequired
will be raised.- Parameters:
notifications (
list
ofNotification
orint
) – The notifications to mark as read. Can be either the notification or its ID.- Raises:
LoginRequired – The Client needs to log in. See
login()
.ValueError – notifications parameter is empty.
- Returns:
datetime
The time when this notification was marked as read.
.. versionadded:: 1.4
- abstract mark_notifications_as_seen(notifications)#
This function can be a coroutine.
Mark
notifications
of the logged inCodinGamer
as seen.You need to be logged in to mark notifications as seen or else a
LoginRequired
will be raised.- Parameters:
notifications (
list
ofNotification
orint
) – The notifications to mark as seen. Can be either the notification or its ID.- Raises:
LoginRequired – The Client needs to log in. See
login()
.ValueError – notifications parameter is empty.
- Returns:
datetime
The time when this notification was marked as seen.
.. versionadded:: 1.4
- request(service, func, parameters=[])#
This function can be a coroutine.
Make a request to the CodinGame API service.
This is useful if you want to use some services that aren’t implemented yet in this library, but you want to use the authentication that this library provides.
Note
The CodinGame API URLs are in the format
https://www.codingame.com/services/{service}/{func}
.- Parameters:
- Raises:
ValueError –
service
orfunction
parameter is empty.HTTPError – Error with the API (service or function not found, wrong number of parameters, bad parameters, etc).
- Returns:
- Anything
The data returned by the CodinGame API, usually a
dict
.
.. versionadded:: 1.2
Synchronous client#
- class codingame.client.sync.SyncClient[source]#
Synchronous client for the CodinGame client.
- login(email=None, password=None, remember_me_cookie=None)[source]#
Login to a CodinGame account.
Error
As of 2021-10-27, the only way to login is with cookie authentication, so with the
remember_me_cookie
parameter, because of an endpoint change, see Login. Using email/password authentication will raise aLoginError
.- Parameters:
email (Optional
str
) – Email adress of the CodinGamer. Not needed if using session ID login.password (Optional
str
) – Password of the CodinGamer. Not needed if using cookie login.remember_me_cookie (Optional
str
) –rememberMe
cookie from CodinGame cookies. Not needed if using email/password login.
- Raises:
LoginError – Error with the login (empty email, empty password, wrong email format, incorrect password, etc).
- Returns:
CodinGamer
The CodinGamer that logged in.
.. versionadded:: 0.3
- get_codingamer(codingamer)[source]#
Get a
CodinGamer
from their public handle, their ID or from their pseudo.Note
codingamer
can be the public handle, the ID or the pseudo. Using the public handle or the ID is reccomended because it won’t change even if the codingamer changes their pseudo.The public handle is a 39 character long hexadecimal string that is unique to the CodinGamer and identifies them. Regex of a public handle:
[0-9a-f]{32}[0-9]{7}
The ID is a 7 number long integer.
- Parameters:
codingamer (
str
orint
) – The CodinGamer’s public handle, ID or pseudo.- Raises:
CodinGamerNotFound – The CodinGamer with the given public handle, ID or pseudo isn’t found.
- Returns:
CodinGamer
The requested CodinGamer.
.. versionadded:: 0.1
.. versionchanged:: 0.2 – Renamed
Client.codingamer()
toget_codingamer()
... versionchanged:: 0.3.3 – Add searching with CodinGamer pseudo.
.. versionchanged:: 0.3.5 – Add searching with CodinGamer ID.
- get_clash_of_code(handle)[source]#
Get a
Clash of Code
from its public handle.- Parameters:
handle (
str
) – The Clash of Code’s public handle. 39 character long hexadecimal string (regex:[0-9]{7}[0-9a-f]{32}
).- Raises:
ValueError – The Clash of Code handle isn’t in the good format.
ClashOfCodeNotFound – The Clash of Code with the given public handle isn’t found.
- Returns:
ClashOfCode
The requested Clash Of Code.
.. versionadded:: 0.2
- get_pending_clash_of_code()[source]#
Get the pending public
Clash of Code
.- Returns:
- Optional
ClashOfCode
The pending Clash Of Code if there’s one, or
None
if there’s no current public Clash Of Code.
- Optional
.. versionadded:: 0.3.2
- create_private_clash_of_code(language_ids=[], modes=[])[source]#
Create a private
Clash of Code
with specified programming languages and modes.You need to be logged in to create a Clash of Code or else a
LoginRequired
will be raised.Note
If an invalid language is given, the API will ignores that language instead of raising an error. This function acts the same way.
- Parameters:
language_ids (
list
ofstr
) – The programming languages allowed in the Clash of Code. Get the list of options withget_language_ids()
. Default: All languages allowed.modes (
list
ofstr
) – The modes from which the Clash of Code mode is chosen from. The valid modes are SHORTEST, FASTEST and REVERSE. Default: All modes allowed.
- Raises:
ValueError – The modes are invalid.
LoginRequired – The Client needs to log in. See
login()
.
- Returns:
ClashOfCode
The created Clash Of Code.
.. versionadded:: 1.5
- join_private_clash_of_code(clash_of_code)[source]#
Join the private
Clash of Code
with the specified handle.You need to be logged in to join a Clash of Code or else a
LoginRequired
will be raised.- Parameters:
handle (
ClashOfCode
orstr
) – The Clash of Code to join or its public handle.- Raises:
ValueError – The Clash of Code handle isn’t in the good format.
LoginRequired – The Client needs to log in. See
login()
.ClashOfCodeFinished – The Clash of Code is already finished.
- Returns:
ClashOfCode
The joined Clash Of Code.
.. versionadded:: 1.5
- get_language_ids()[source]#
Get the list of all available language IDs.
- Returns:
.. versionadded:: 0.3
.. versionchanged:: 1.0 – Renamed
Client.language_ids
toget_language_ids()
.
- get_unseen_notifications()[source]#
Get all the unseen
notifications
of the logged inCodinGamer
.You need to be logged in to get notifications or else a
LoginRequired
will be raised.Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– An unseen notification.
New in version 0.3.1.
Changed in version 1.0: Renamed
Client.notifications
toget_unseen_notifications()
.
- get_unread_notifications()[source]#
Get all the unread
notifications
of the logged inCodinGamer
.This includes unseen notifications along with the unread ones.
You need to be logged in to get notifications or else a
LoginRequired
will be raised.Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– An unread notification.
New in version 1.3.
- get_read_notifications()[source]#
Get the read
notifications
of the logged inCodinGamer
.You need to be logged in to get notifications or else a
LoginRequired
will be raised.Warning
There can be some old notifications missing.
Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– A read notification.
New in version 1.3.
- mark_notifications_as_seen(notifications)[source]#
Mark
notifications
of the logged inCodinGamer
as seen.You need to be logged in to mark notifications as seen or else a
LoginRequired
will be raised.- Parameters:
notifications (
list
ofNotification
orint
) – The notifications to mark as seen. Can be either the notification or its ID.- Raises:
LoginRequired – The Client needs to log in. See
login()
.ValueError – notifications parameter is empty.
- Returns:
datetime
The time when this notification was marked as seen.
.. versionadded:: 1.4
- mark_notifications_as_read(notifications)[source]#
Mark
notifications
of the logged inCodinGamer
as read.You need to be logged in to mark notifications as read or else a
LoginRequired
will be raised.- Parameters:
notifications (
list
ofNotification
orint
) – The notifications to mark as read. Can be either the notification or its ID.- Raises:
LoginRequired – The Client needs to log in. See
login()
.ValueError – notifications parameter is empty.
- Returns:
datetime
The time when this notification was marked as read.
.. versionadded:: 1.4
- get_global_leaderboard(page=1, type='GENERAL', group='global')[source]#
Get the
global leaderboard
of CodinGame.You can specify an optional page, type of leaderboard and the group of users to rank.
- Parameters:
page (Optional
int
) – The page of the leaderboard to get the users from. Default:1
.type (Optional
str
) – The type of global leaderboard to show. One of"GENERAL"
,"CONTESTS"
,"BOT_PROGRAMMING"
,"OPTIM"
or"CODEGOLF"
. Default:"GENERAL"
.group (Optional
str
) – The group of users to rank. For every group except"global"
, you need to be logged in. One of"global"
,"country"
,"company"
,"school"
or"following"
. Default:"global"
.
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.
- Returns:
GlobalLeaderboard
The global leaderboard of CodinGame.
.. versionadded:: 0.4
- get_challenge_leaderboard(challenge_id, group='global')[source]#
Get the
leaderboard of a challenge
.You can specify an optional group of users to rank.
- Parameters:
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.ChallengeNotFound – There is no challenge with the given
challenge_id
.
- Returns:
ChallengeLeaderboard
The leaderboard of the requested challenge.
.. versionadded:: 0.4
- get_puzzle_leaderboard(puzzle_id, group='global')[source]#
Get the
leaderboard of a puzzle
.You can specify an optional group of users to rank.
- Parameters:
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.PuzzleNotFound – There is no puzzle with the given
puzzle_id
.
- Returns:
PuzzleLeaderboard
The leaderboard of the requested puzzle.
.. versionadded:: 0.4
- property codingamer#
The CodinGamer that is logged in.
None
if the client isn’t logged in.- Type:
Optional
CodinGamer
- request(service, func, parameters=[])#
This function can be a coroutine.
Make a request to the CodinGame API service.
This is useful if you want to use some services that aren’t implemented yet in this library, but you want to use the authentication that this library provides.
Note
The CodinGame API URLs are in the format
https://www.codingame.com/services/{service}/{func}
.- Parameters:
- Raises:
ValueError –
service
orfunction
parameter is empty.HTTPError – Error with the API (service or function not found, wrong number of parameters, bad parameters, etc).
- Returns:
- Anything
The data returned by the CodinGame API, usually a
dict
.
.. versionadded:: 1.2
Asynchronous client#
- class codingame.client.async_.AsyncClient[source]#
Asynchronous client for the CodinGame API.
- async login(email=None, password=None, remember_me_cookie=None)[source]#
This function is a coroutine.
Login to a CodinGame account.
Error
As of 2021-10-27, the only way to login is with cookie authentication, so with the
remember_me_cookie
parameter, because of an endpoint change, see Login. Using email/password authentication will raise aLoginError
.- Parameters:
email (Optional
str
) – Email adress of the CodinGamer. Not needed if using session ID login.password (Optional
str
) – Password of the CodinGamer. Not needed if using cookie login.remember_me_cookie (Optional
str
) –rememberMe
cookie from CodinGame cookies. Not needed if using email/password login.
- Raises:
LoginError – Error with the login (empty email, empty password, wrong email format, incorrect password, etc).
- Returns:
CodinGamer
The CodinGamer that logged in.
.. versionadded:: 0.3
- async get_codingamer(codingamer)[source]#
This function is a coroutine.
Get a
CodinGamer
from their public handle, their ID or from their pseudo.Note
codingamer
can be the public handle, the ID or the pseudo. Using the public handle or the ID is reccomended because it won’t change even if the codingamer changes their pseudo.The public handle is a 39 character long hexadecimal string that is unique to the CodinGamer and identifies them. Regex of a public handle:
[0-9a-f]{32}[0-9]{7}
The ID is a 7 number long integer.
- Parameters:
codingamer (
str
orint
) – The CodinGamer’s public handle, ID or pseudo.- Raises:
CodinGamerNotFound – The CodinGamer with the given public handle, ID or pseudo isn’t found.
- Returns:
CodinGamer
The requested CodinGamer.
.. versionadded:: 0.1
.. versionchanged:: 0.2 – Renamed
Client.codingamer()
toget_codingamer()
... versionchanged:: 0.3.3 – Add searching with CodinGamer pseudo.
.. versionchanged:: 0.3.5 – Add searching with CodinGamer ID.
- async get_clash_of_code(handle)[source]#
This function is a coroutine.
Get a
Clash of Code
from its public handle.- Parameters:
handle (
str
) – The Clash of Code’s public handle. 39 character long hexadecimal string (regex:[0-9]{7}[0-9a-f]{32}
).- Raises:
ValueError – The Clash of Code handle isn’t in the good format.
ClashOfCodeNotFound – The Clash of Code with the given public handle isn’t found.
- Returns:
ClashOfCode
The requested Clash Of Code.
.. versionadded:: 0.2
- async get_pending_clash_of_code()[source]#
This function is a coroutine.
Get the pending public
Clash of Code
.- Returns:
- Optional
ClashOfCode
The pending Clash Of Code if there’s one, or
None
if there’s no current public Clash Of Code.
- Optional
.. versionadded:: 0.3.2
- async create_private_clash_of_code(language_ids=[], modes=[])[source]#
This function is a coroutine.
Create a private
Clash of Code
with specified programming languages and modes.You need to be logged in to create a Clash of Code or else a
LoginRequired
will be raised.Note
If an invalid language is given, the API will ignores that language instead of raising an error. This function acts the same way.
- Parameters:
language_ids (
list
ofstr
) – The programming languages allowed in the Clash of Code. Get the list of options withget_language_ids()
. Default: All languages allowed.modes (
list
ofstr
) – The modes from which the Clash of Code mode is chosen from. The valid modes are SHORTEST, FASTEST and REVERSE. Default: All modes allowed.
- Raises:
ValueError – The modes are invalid.
LoginRequired – The Client needs to log in. See
login()
.
- Returns:
ClashOfCode
The created Clash Of Code.
.. versionadded:: 1.5
- async join_private_clash_of_code(clash_of_code)[source]#
This function is a coroutine.
Join the private
Clash of Code
with the specified handle.You need to be logged in to join a Clash of Code or else a
LoginRequired
will be raised.- Parameters:
handle (
ClashOfCode
orstr
) – The Clash of Code to join or its public handle.- Raises:
ValueError – The Clash of Code handle isn’t in the good format.
LoginRequired – The Client needs to log in. See
login()
.ClashOfCodeFinished – The Clash of Code is already finished.
- Returns:
ClashOfCode
The joined Clash Of Code.
.. versionadded:: 1.5
- async get_language_ids()[source]#
This function is a coroutine.
Get the list of all available language IDs.
- Returns:
.. versionadded:: 0.3
.. versionchanged:: 1.0 – Renamed
Client.language_ids
toget_language_ids()
.
- async get_unseen_notifications()[source]#
This function is a coroutine.
Get all the unseen
notifications
of the logged inCodinGamer
.You need to be logged in to get notifications or else a
LoginRequired
will be raised.Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– An unseen notification.
New in version 0.3.1.
Changed in version 1.0: Renamed
Client.notifications
toget_unseen_notifications()
.
- async get_unread_notifications()[source]#
This function is a coroutine.
Get all the unread
notifications
of the logged inCodinGamer
.This includes unseen notifications along with the unread ones.
You need to be logged in to get notifications or else a
LoginRequired
will be raised.Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– An unread notification.
New in version 1.3.
- async get_read_notifications()[source]#
This function is a coroutine.
Get the read
notifications
of the logged inCodinGamer
.You need to be logged in to get notifications or else a
LoginRequired
will be raised.Warning
There can be some old notifications missing.
Note
This method is a generator.
- Raises:
LoginRequired – The Client needs to log in. See
login()
.- Yields:
Notification
– A read notification.
New in version 1.3.
- async mark_notifications_as_seen(notifications)[source]#
This function is a coroutine.
Mark
notifications
of the logged inCodinGamer
as seen.You need to be logged in to mark notifications as seen or else a
LoginRequired
will be raised.- Parameters:
notifications (
list
ofNotification
orint
) – The notifications to mark as seen. Can be either the notification or its ID.- Raises:
LoginRequired – The Client needs to log in. See
login()
.ValueError – notifications parameter is empty.
- Returns:
datetime
The time when this notification was marked as seen.
.. versionadded:: 1.4
- async mark_notifications_as_read(notifications)[source]#
This function is a coroutine.
Mark
notifications
of the logged inCodinGamer
as read.You need to be logged in to mark notifications as read or else a
LoginRequired
will be raised.- Parameters:
notifications (
list
ofNotification
orint
) – The notifications to mark as read. Can be either the notification or its ID.- Raises:
LoginRequired – The Client needs to log in. See
login()
.ValueError – notifications parameter is empty.
- Returns:
datetime
The time when this notification was marked as read.
.. versionadded:: 1.4
- async get_global_leaderboard(page=1, type='GENERAL', group='global')[source]#
This function is a coroutine.
Get the
global leaderboard
of CodinGame.You can specify an optional page, type of leaderboard and the group of users to rank.
- Parameters:
page (Optional
int
) – The page of the leaderboard to get the users from. Default:1
.type (Optional
str
) – The type of global leaderboard to show. One of"GENERAL"
,"CONTESTS"
,"BOT_PROGRAMMING"
,"OPTIM"
or"CODEGOLF"
. Default:"GENERAL"
.group (Optional
str
) – The group of users to rank. For every group except"global"
, you need to be logged in. One of"global"
,"country"
,"company"
,"school"
or"following"
. Default:"global"
.
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.
- Returns:
GlobalLeaderboard
The global leaderboard of CodinGame.
.. versionadded:: 0.4
- async get_challenge_leaderboard(challenge_id, group='global')[source]#
This function is a coroutine.
Get the
leaderboard of a challenge
.You can specify an optional group of users to rank.
- Parameters:
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.ChallengeNotFound – There is no challenge with the given
challenge_id
.
- Returns:
ChallengeLeaderboard
The leaderboard of the requested challenge.
.. versionadded:: 0.4
- async get_puzzle_leaderboard(puzzle_id, group='global')[source]#
This function is a coroutine.
Get the
leaderboard of a puzzle
.You can specify an optional group of users to rank.
- Parameters:
- Raises:
ValueError – One of the arguments isn’t one of the accepted arguments.
LoginRequired – The client isn’t logged in and the group is one of
"country"
,"company"
,"school"
or"following"
.PuzzleNotFound – There is no puzzle with the given
puzzle_id
.
- Returns:
PuzzleLeaderboard
The leaderboard of the requested puzzle.
.. versionadded:: 0.4
- property codingamer#
The CodinGamer that is logged in.
None
if the client isn’t logged in.- Type:
Optional
CodinGamer
- request(service, func, parameters=[])#
This function can be a coroutine.
Make a request to the CodinGame API service.
This is useful if you want to use some services that aren’t implemented yet in this library, but you want to use the authentication that this library provides.
Note
The CodinGame API URLs are in the format
https://www.codingame.com/services/{service}/{func}
.- Parameters:
- Raises:
ValueError –
service
orfunction
parameter is empty.HTTPError – Error with the API (service or function not found, wrong number of parameters, bad parameters, etc).
- Returns:
- Anything
The data returned by the CodinGame API, usually a
dict
.
.. versionadded:: 1.2
CodinGame Models#
Models are classes that are created from the data received from CodinGame and are not meant to be created by the user of the library.
Danger
The classes listed below are not intended to be created by users and are also read-only.
For example, this means that you should not make your own
CodinGamer
instances nor should you modify the CodinGamer
instance yourself.
CodinGamer#
- class codingame.PartialCodinGamer(state, data)[source]#
Represents a partial CodinGamer.
This class doesn’t have all the data of a CodinGamer. Use
client.get_codingamer(partial_codingamer.public_handle)
for that.- id#
ID of the CodinGamer. Last 7 digits of the
public_handle
reversed.- Type:
- avatar#
Avatar ID of the CodinGamer. You can get the avatar url with
avatar_url
.- Type:
Optional
int
- get_followers()[source]#
This function can be a coroutine.
Get all the followers of a CodinGamer.
You need to be logged in to get the followers or else a
LoginRequired
will be raised. If you can’t log in, you can useCodinGamer.get_followers_ids()
instead.Note
This property is a generator.
Warning
The
xp
attribute of the following codingamers isNone
.- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.- Yields:
CodinGamer
– The follower.
- get_followers_ids()[source]#
This function can be a coroutine.
Get all the IDs of the followers of a CodinGamer.
- Returns:
list
ofint
The CodinGamer’s followers IDs. See
CodinGamer.id
.
- get_followed()[source]#
This function can be a coroutine.
Get all the followed CodinGamers.
You need to be logged in to get the followed CodinGamers or else a
LoginRequired
will be raised. If you can’t log in, you can useCodinGamer.get_followed_ids()
instead.Note
This property is a generator.
Warning
The
xp
attribute of the followed codingamers isNone
.- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.- Yields:
CodinGamer
– The followed CodinGamer.
- class codingame.CodinGamer(state, data)[source]#
Represents a CodinGamer.
- id#
ID of the CodinGamer. Last 7 digits of the
public_handle
reversed.- Type:
- category#
Category of the CodinGamer. Can be
STUDENT
orPROFESSIONAL
.Note
You can use
student
andprofessional
to get abool
that describes the CodinGamer’s category.- Type:
Optional
str
- avatar#
Avatar ID of the CodinGamer. You can get the avatar url with
avatar_url
.- Type:
Optional
int
- get_clash_of_code_rank()#
This function can be a coroutine.
Get the Clash of Code rank of the CodinGamer.
- Returns:
int
The Clash of Code rank of the CodinGamer.
- get_followed()#
This function can be a coroutine.
Get all the followed CodinGamers.
You need to be logged in to get the followed CodinGamers or else a
LoginRequired
will be raised. If you can’t log in, you can useCodinGamer.get_followed_ids()
instead.Note
This property is a generator.
Warning
The
xp
attribute of the followed codingamers isNone
.- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.- Yields:
CodinGamer
– The followed CodinGamer.
- get_followed_ids()#
This function can be a coroutine.
Get all the IDs of the followed CodinGamers.
- Returns:
list
ofint
The IDs of the followed CodinGamers. See
CodinGamer.id
.
- get_followers()#
This function can be a coroutine.
Get all the followers of a CodinGamer.
You need to be logged in to get the followers or else a
LoginRequired
will be raised. If you can’t log in, you can useCodinGamer.get_followers_ids()
instead.Note
This property is a generator.
Warning
The
xp
attribute of the following codingamers isNone
.- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.- Yields:
CodinGamer
– The follower.
- get_followers_ids()#
This function can be a coroutine.
Get all the IDs of the followers of a CodinGamer.
- Returns:
list
ofint
The CodinGamer’s followers IDs. See
CodinGamer.id
.
Clash of Code#
- class codingame.ClashOfCode(state, data)[source]#
Represents a Clash of Code.
- start_time#
Start time of the Clash of Code. If the Clash of Code hasn’t started yet, this is the expected start time of the Clash of Code.
- Type:
- fetch()[source]#
This function can be a coroutine.
Get and update the information about this Clash Of Code.
This modifies this object’s own attributes in place.
- join(refetch=False)[source]#
This function can be a coroutine.
Join this Clash Of Code.
You need to be logged in to join a Clash of Code or else a
LoginRequired
will be raised.- Parameters:
refetch (
bool
) – Whether to update this object after joining. Default: False- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.
- start(refetch=False)[source]#
This function can be a coroutine.
Start this Clash Of Code.
You need to be logged in as the owner to start a Clash of Code or else a
LoginRequired
will be raised.Note
This sets the countdown to the start to 5s. You will need to fetch the Clash Of Code again in 5-10s.
- Parameters:
refetch (
bool
) – Whether to update this object after starting. Default: False- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.
- leave(refetch=False)[source]#
This function can be a coroutine.
Leave this Clash Of Code.
You need to be logged in or else a
LoginRequired
will be raised.- Parameters:
refetch (
bool
) – Whether to update this object after leaving. Default: False- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.
- get_question(refetch=False)[source]#
This function can be a coroutine.
Get the question for this Clash of Code.
You need to be logged in or else a
LoginRequired
will be raised.- Parameters:
refetch (
bool
) – Whether to update this object after getting the question. Default: False- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.
- play_test_cases(language_id, code, indexes=None, refetch=False)[source]#
This function can be a coroutine.
Play test cases for this Clash of Code with the given code.
You need to be logged in or else a
LoginRequired
will be raised.- Parameters:
language_id (
str
) – The language ID of the used programming language.code (
str
) – The code to test against the test cases.indexes (
list
ofint
) – The indexes of the test cases to test the code. Default: all test casesrefetch (
bool
) – Whether to update this object after getting the question. Default: False
- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.
- submit(language_id, code, share=False, refetch=False)[source]#
This function can be a coroutine.
Submit your solution for this Clash of Code.
You need to be logged in or else a
LoginRequired
will be raised.- Parameters:
- Raises:
LoginRequired – The Client needs to log in. See
Client.login()
.
- class codingame.Player(state, clash_of_code, started, finished, data)[source]#
Represents a Clash of Code player.
- clash_of_code#
Clash of Code the Player belongs to.
- Type:
- public_handle#
Public handle of the CodinGamer (hexadecimal str). Sometimes missing, prefer
id
.- Type:
- id#
ID of the CodinGamer. Last 7 digits of the
public_handle
reversed.- Type:
- avatar#
Avatar ID of the CodinGamer. You can get the avatar url with
avatar_url
.- Type:
Optional
int
- rank#
Rank of the Player. Only use this when the Clash of Code is finished because it isn’t precise until then.
- Type:
Optional
int
- duration#
Time taken by the player to solve the problem of the Clash of Code.
- Type:
Optional
timedelta
- code_length#
Length of the Player’s code. Only available when the Clash of Code’s mode is
SHORTEST
.- Type:
Optional
int
Whether the Player shared their code.
- Type:
Optional
bool
Notification#
- class codingame.Notification(state, data)[source]#
Represents a Notification.
- type_group#
Group type of the notification.
- Type:
- type#
Precise type of the notification.
- Type:
- data#
Data of the notification.
Note
Every notification type has different data. So there isn’t the same keys and values every time.
- Type:
Optional
dict
- codingamer#
CodinGamer that sent the notification, only appears in some notification types.
- Type:
Optional
PartialCodinGamer
- mark_as_seen()[source]#
This function can be a coroutine.
Mark this notification as seen.
Warning
If you want to mark multiple notifications as seen at the same time, use
Client.mark_notifications_as_seen()
as it only makes one API request for all the notifications instead of one API request for each notification.- Returns:
datetime
The time when this notification was marked as seen.
.. versionadded:: 1.4
- mark_as_read()[source]#
This function can be a coroutine.
Mark this notification as read.
Warning
If you want to mark multiple notifications as read at the same time, use
Client.mark_notifications_as_read()
as it only makes one API request for all the notifications instead of one API request for each notification.- Returns:
datetime
The time when this notification was marked as read.
.. versionadded:: 1.4
Enumerations#
- class codingame.NotificationTypeGroup[source]#
Enumeration for the
Notification.type_group
.Warning
There might be some missing type groups.
- class codingame.NotificationType[source]#
Enumeration for the
Notification.type
.- new_league = 'new-league'#
Type:
str
When a new league is added to an arena.
If the new league is higher than your current one, you will get demoted, otherwise your league will stay the same.
- eligible_for_next_league = 'eligible-for-next-league'#
Type:
str
When you are better than the boss of your current league.
This means you will be promoted soon.
- contribution_clash_mode_removed = 'contribution-clash-mode-removed'#
Type:
str
When your contribution is modified.
- contribution_moderated = 'contribution-moderated'#
Type:
str
When your contribution is validated or denied.
- new_league_opened = 'new-league-opened'#
Type:
str
When a new league is opened.
I don’t know why this isn’t in
NotificationTypeGroup.arena
likeNotificationType.new_league
,NotificationType.eligible_for_next_league
andNotificationType.promoted_league
.
Notification data#
- class codingame.LanguageMapping(state, mapping)[source]#
Mapping to store text with multiple languages.
This class has the same interface as
dict
for backwards compatibility.
- class codingame.NotificationData(state, data)[source]#
Base class for the notification data classes.
This class has the same interface as
dict
for backwards compatibility.- _raw#
Raw data of the
Notification
, useful when one of the values isn’t an attribute.- Type:
- classmethod from_type(type, state, data)[source]#
Create the correct
NotificationData
subclass according to thenotification type
.- Parameters:
type (
NotificationType
) – The notification type.data (
dict
) – The notification data.
- Returns:
NotificationData
The parsed data of the notifcation.
- class codingame.AchievementUnlockedData(state, data)[source]#
Data of a
NotificationType.achievement_unlocked
notification.- label#
Type:
LanguageMapping
- class codingame.LeagueData(state, data)[source]#
Data of
NotificationType.new_league
,NotificationType.eligible_for_next_league
,NotificationType.promoted_league
andNotificationType.new_league_opened
notifications.- title_label#
Type:
LanguageMapping
- class codingame.NewBlogData(state, data)[source]#
Data of a
NotificationType.new_blog
notification.- title#
Type:
LanguageMapping
- url#
Type:
LanguageMapping
- class codingame.ClashInviteData(state, data)[source]#
Data of a
NotificationType.clash_invite
notification.
- class codingame.ClashOverData(state, data)[source]#
Data of a
NotificationType.clash_over
notification.
- class codingame.Contribution(state, data)[source]#
Data about a contribution.
This class has the same interface as
dict
for backwards compatibility.
- class codingame.PuzzleSolution(state, data)[source]#
Data about a puzzle solution.
This class has the same interface as
dict
for backwards compatibility.
- class codingame.NewCommentData(state, data)[source]#
Data of a
NotificationType.new_comment
andNotificationType.new_comment_response
notifications.- type#
Type:
LanguageMapping
- class codingame.ContributionData(state, data)[source]#
Data of
NotificationType.contribution_received
,NotificationType.contribution_accepted
,NotificationType.contribution_refused
andNotificationType.contribution_clash_mode_removed
notifications.
- class codingame.FeatureData(state, data)[source]#
Data of a
NotificationType.feature
notification.- description#
Type:
LanguageMapping
- class codingame.NewHintData(state, data)[source]#
Data of a
NotificationType.new_hint
notification.- puzzle_title#
Type:
LanguageMapping
- class codingame.ContributionModeratedData(state, data)[source]#
Data of a
NotificationType.contribution_moderated
notification.- action_type#
Type:
ContributionModeratedActionType
- contribution#
Type:
Contribution
- class codingame.NewPuzzleData(state, data)[source]#
Data of a
NotificationType.new_puzzle
notification.- level#
Type:
LanguageMapping
- name#
Type:
LanguageMapping
- class codingame.PuzzleOfTheWeekData(state, data)[source]#
Data of a
NotificationType.puzzle_of_the_week
notification.- puzzle_name#
Type:
LanguageMapping
- class codingame.QuestCompletedData(state, data)[source]#
Data of a
NotificationType.quest_completed
notification.- label#
Type:
LanguageMapping
- class codingame.FriendRegisteredData(state, data)[source]#
Data of a
NotificationType.friend_registered
notification.
- class codingame.NewLevelData(state, data)[source]#
Data of a
NotificationType.new_level
notification.
- class codingame.GenericData(state, data)[source]#
Data of a
NotificationType.info_generic
,NotificationType.warning_generic
andNotificationType.important_generic
notifications.- title#
Type:
LanguageMapping
- description#
Type:
LanguageMapping
- class codingame.CustomData(state, data)[source]#
Data of a
NotificationType.custom
notification.- title#
Type:
LanguageMapping
- description#
Type:
LanguageMapping
- class codingame.CareerCandidateData(state, data)[source]#
Data of a
NotificationType.career_new_candidate
andNotificationType.career_update_candidate
notifications.
- class codingame.TestFinishedData(state, data)[source]#
Data of a
NotificationType.test_finished
notification.
- class codingame.JobAcceptedData(state, data)[source]#
Data of a
NotificationType.job_accepted
notification.
- class codingame.JobExpiredData(state, data)[source]#
Data of a
NotificationType.job_expired
notification.
- class codingame.NewWorkBlogData(state, data)[source]#
Data of a
NotificationType.new_work_blog
notification.- title#
Type:
LanguageMapping
- url#
Type:
LanguageMapping
- class codingame.OfferApplyData(state, data)[source]#
Data of a
NotificationType.offer_apply
notification.
Leaderboards#
Global leaderboard#
- class codingame.GlobalRankedCodinGamer(state, leaderboard, data)[source]#
Ranked CodinGamer in global leaderboard.
- leaderboard#
Type:
GlobalLeaderboard
- avatar#
Type:
MemberDescriptorType
- category#
Type:
MemberDescriptorType
- company#
Type:
MemberDescriptorType
- country_id#
Type:
MemberDescriptorType
- cover#
Type:
MemberDescriptorType
- id#
Type:
MemberDescriptorType
- level#
Type:
MemberDescriptorType
- professional#
Type:
MemberDescriptorType
- pseudo#
Type:
MemberDescriptorType
- public_handle#
Type:
MemberDescriptorType
- rank#
Type:
MemberDescriptorType
- school#
Type:
MemberDescriptorType
- score#
Type:
MemberDescriptorType
- student#
Type:
MemberDescriptorType
- class codingame.GlobalLeaderboard(state, lb_type, group, page, data)[source]#
Global leaderboard.
- type#
Type:
str
Global leaderboard type. One of
"GENERAL"
,"CONTESTS"
,"BOT_PROGRAMMING"
,"OPTIM"
,"CODEGOLF"
.
- group#
Type:
str
Group of CodinGamer who are ranked. One of
"global"
,"country"
,"company"
,"school"
,"following"
.
- count#
Type:
MemberDescriptorType
Challenge leaderboard#
- class codingame.ChallengeRankedCodinGamer(state, leaderboard, data)[source]#
Ranked CodinGamer in challenge leaderboards.
- avatar#
Type:
MemberDescriptorType
- category#
Type:
MemberDescriptorType
- company#
Type:
MemberDescriptorType
- country_id#
Type:
MemberDescriptorType
- cover#
Type:
MemberDescriptorType
- id#
Type:
MemberDescriptorType
- level#
Type:
MemberDescriptorType
- professional#
Type:
MemberDescriptorType
- pseudo#
Type:
MemberDescriptorType
- public_handle#
Type:
MemberDescriptorType
- rank#
Type:
MemberDescriptorType
- school#
Type:
MemberDescriptorType
- score#
Type:
MemberDescriptorType
- student#
Type:
MemberDescriptorType
- leaderboard#
Type:
ChallengeLeaderboard
The leaderboard that this CodinGamer is part of.
- progress#
-
Progress of the CodinGamer. I don’t understand what this is, so if you know, please join the support server and tell me.
Puzzle leaderboard#
- class codingame.PuzzleRankedCodinGamer(state, leaderboard, data)[source]#
Ranked CodinGamer in puzzle leaderboards.
- avatar#
Type:
MemberDescriptorType
- category#
Type:
MemberDescriptorType
- company#
Type:
MemberDescriptorType
- country_id#
Type:
MemberDescriptorType
- cover#
Type:
MemberDescriptorType
- id#
Type:
MemberDescriptorType
- level#
Type:
MemberDescriptorType
- professional#
Type:
MemberDescriptorType
- pseudo#
Type:
MemberDescriptorType
- public_handle#
Type:
MemberDescriptorType
- rank#
Type:
MemberDescriptorType
- school#
Type:
MemberDescriptorType
- score#
Type:
MemberDescriptorType
- student#
Type:
MemberDescriptorType
- leaderboard#
Type:
PuzzleLeaderboard
The leaderboard that this CodinGamer is part of.
- progress#
-
Progress of the CodinGamer. I don’t understand what this is, so if you know, please join the support server and tell me.
Exceptions#
The following exceptions are thrown by the library.
- exception codingame.MalformedEmail(message)[source]#
Raised when the email given at login isn’t well formed.
- exception codingame.PasswordRequired(message)[source]#
Raised when the password given at login is empty.
- exception codingame.EmailNotLinked(message)[source]#
Raised when the email given at login isn’t linked to a CodinGamer account.
- exception codingame.IncorrectPassword(message)[source]#
Raised when the password given at login is incorrect.
- exception codingame.WrongCaptchaAnswer(message)[source]#
Raised when the captcha in the email/password login is incorrect.
See Login to fix this
- exception codingame.LoginRequired(message=None)[source]#
Raised when an action requires the client to log in.
- exception codingame.ClashOfCodeError(message)[source]#
Raised when there is an error with a Clash of Code.
- exception codingame.ClashOfCodeCancelled(message)[source]#
Raised when trying to join a Clash of Code that was cancelled.
- exception codingame.ClashOfCodeStarted(message)[source]#
Raised when trying to join an already started Clash of Code.
- exception codingame.ClashOfCodeFinished(message)[source]#
Raised when trying to join an already finished Clash of Code.
- exception codingame.ClashOfCodeFull(message)[source]#
Raised when trying to join a Clash of Code that reached the maximum number of players.