Skip to main content

A high-performance and type-safe Python library for seamless interaction with the Codeforces API. Supports both asynchronous and synchronous client handlers, enabling developers to choose the best approach for their needs.

Project description

codeforcespy

PyPI Python 3.13+ License: GPL-3.0 Type Safe

A fast, type-safe Python wrapper for the Codeforces API with sync and async support.

codeforcespy

Features

  • Sync & Async - Full support for both blocking and non-blocking clients
  • Type Safe - 100% typed, no Any, passes strict pyright
  • Fast - Built on httpx and msgspec for high performance
  • Complete - Covers all public Codeforces API endpoints

Installation

pip install codeforcespy

Quick Start

Async Client (Recommended)

import asyncio
import codeforcespy.processors

async def main():
    client = codeforcespy.processors.AsyncMethod()
    
    try:
        # Get user info
        users = await client.get_user(handles="tourist")
        print(f"{users[0].handle}: {users[0].rating}")
        
        # Get recent contests
        contests = await client.get_contest_list()
        print(f"Found {len(contests)} contests")
    finally:
        await client.close()

asyncio.run(main())

Sync Client

import codeforcespy.processors

client = codeforcespy.processors.SyncMethod()

try:
    users = client.get_user(handles="tourist")
    print(f"{users[0].handle}: {users[0].rating}")
finally:
    client.close()

API Methods

User

Method Description
get_user(handles) Get user profile(s) by handle
get_user_rating(handle) Get rating history
get_user_status(handle, count) Get recent submissions
get_user_friends(only_online) Get friends list (auth required)
get_user_blog_entries(handle) Get user's blog posts
get_user_rated_list(...) Get rated users list

Contest

Method Description
get_contest_list(of_gym) List all contests
get_contest_standings(...) Get contest standings
get_contest_status(contest_id) Get contest submissions
get_contest_hacks(contest_id) Get contest hacks
get_contest_rating_changes(contest_id) Get rating changes

Problemset

Method Description
get_problemset_problems(tags) Get problems by tags
get_problemset_recent_status(count) Get recent submissions

Blog & Recent

Method Description
get_blog_entry_view(blog_entry_id) Get blog post
get_blog_entry_comments(blog_entry_id) Get blog comments
get_recent_actions(max_count) Get recent platform activity

Authentication

For authenticated endpoints (friends, private data):

client = codeforcespy.processors.AsyncMethod(
    enable_auth=True,
    auth_key="YOUR_API_KEY",
    secret="YOUR_API_SECRET",
)

Get your API key at codeforces.com/settings/api.

Error Handling

import codeforcespy.errors
import codeforcespy.processors

client = codeforcespy.processors.SyncMethod()

try:
    users = client.get_user(handles="nonexistent_user_12345")
except codeforcespy.errors.APIError as e:
    print(f"API error: {e.message}")
except codeforcespy.errors.CodeforcesPyError as e:
    print(f"Library error: {e.message}")

Examples

See the examples/ directory for complete working examples:

  • sync_example.py - Synchronous client usage
  • async_example.py - Asynchronous client with concurrent requests

License

GPL-3.0 License - see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codeforcespy-1.2.1.tar.gz (35.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

codeforcespy-1.2.1-py3-none-any.whl (39.3 kB view details)

Uploaded Python 3

File details

Details for the file codeforcespy-1.2.1.tar.gz.

File metadata

  • Download URL: codeforcespy-1.2.1.tar.gz
  • Upload date:
  • Size: 35.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for codeforcespy-1.2.1.tar.gz
Algorithm Hash digest
SHA256 6cdd10c972a0c3ecc27173e0ad01c048a6b766a4f781b7a0d55d347e2acaca5a
MD5 8b471250d9e1450d6641eab5016df5cc
BLAKE2b-256 e10f6f9bd82b8616e3569289e74a38d001cd62881341e12986ea89fddf0ce808

See more details on using hashes here.

File details

Details for the file codeforcespy-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: codeforcespy-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 39.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.25

File hashes

Hashes for codeforcespy-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6bbb235f5179ac5598508106faf319386f06a6581e665680ee8bf06cecc4741c
MD5 a66d6ca2d77705f9c8f4d58713c7cee8
BLAKE2b-256 340cae87ef3f43187af6c47f0e02a96b073653d20a7482a9fcb8b6498514a599

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page