Welcome to python-codeforces’s documentation!

Quickstart

Installation

python-codeforces can be installed using pip as follows:

pip install python-codeforces

Installation from source can be done from the root of the project with the following command.

pip install .

Using python-codeforces

Introduction

Direct API calls can be made with the codeforces.api.call function. For Example:

>>> from codeforces import api
>>> api.call('user.info', handles="mukundan314")
[{'lastName': 'Senthil', 'country': 'India', 'lastOnlineTimeSeconds': 1547349164, 'city': 'Coimbatore', 'rating': 1495, 'friendOfCount': 4, 'titlePhoto': '//userpic.codeforces.com/765517/title/93ffab462a95eb16.jpg', 'handle': 'Mukundan314', 'avatar': '//userpic.codeforces.com/765517/avatar/b0cea461ab905c83.jpg', 'firstName': 'Mukundan', 'contribution': 0, 'organization': 'Block Lab', 'rank': 'specialist', 'maxRating': 1502, 'registrationTimeSeconds': 1531657670, 'email': 'mukundan314@gmail.com', 'maxRank': 'specialist'}]

Authorization

To make authorized API calls you need to generate a API key at https://codeforces.com/settings/api.

And when making authorized call:

from codeforces import api

api_key = "xxx"
api_secret = "yyy"

api.call("method_name", key=api_key, secret=api_secret, arg=arg_for_method)

API

codeforces

api

Functions to call the codeforces api

codeforces.api.call(method, key=None, secret=None, **kwargs)

Call a Codeforces API method

Parameters:
  • method (str) – Name of method to call, list of all methods can be found at https://codeforces.com/api/help.
  • key (str, optional) – Your api key (needed for authorized calls)
  • secret (str, optional) – Secret for your api key.
  • **kwargs – Arguments for the api call
Returns:

A python object containing the results of the api call.

Return type:

any

problem

codeforces.problem.get_info(contest_id, index, lang='en')

Get info for a contest problem.

Parameters:
  • contest_id (int) – Id of the contest. It is not the round number. It can be seen in contest URL. For example: /contest/566/status
  • index (str) – Usually a letter of a letter, followed by a digit, that represent a problem index in a contest. It can be seen in problem URL. For example: /contest/566/A
Returns:

  • title (str) – Title of the problem.
  • time_limit (str) – Time limit specification for the problem.
  • memory_limit (str) – Memory limit specification for the problem.
  • sample_tests (zip) – Sample tests given for the problem.

error

exception codeforces.error.CodeforcesAPIError(comment, method, args)

Indices and tables