Skip to main content

A Python library for interacting with Codeforces API and automating tasks.

Project description

cf_helper Library

A Python library for interacting with the Codeforces API, allowing you to fetch user information, ratings, problems, contests, and more.

Table of Contents

Installation

To use cf_helper, you need to install the library. Make sure you have pip installed on your system.

pip install cf-helper

API Key Setup

To access private data via the Codeforces API, you'll need to generate an API key:

  1. Go to Codeforces: Visit https://codeforces.com/settings/api.
  2. Create a new API Key: Provide a name for the key, and Codeforces will generate two parameters:
    • Key: The public part of the API key.
    • Secret: A private, secret part used for signing requests.
  3. Store the Key and Secret:
    • Add your key and secret to an environment variable file (e.g., .env):
      key="your_api_key"
      secret="your_api_secret"
      

Usage

  1. Importing Functions

    from cf_helper.utility import *
    from dotenv import load_dotenv
    import os
    
    load_dotenv()
    key = os.getenv("key")
    secret = os.getenv("secret")
    
    if __name__ == "__main__":
        handle = "CodeLegendX"
    
  2. Fetch User Information

    user_info = get_user_info(handle)
    print("\nUser Info:")
    print(user_info)
    
  3. Fetch User Status

    user_status = get_user_status(handle)
    print("\nUser Status:")
    for status in user_status[:2]:
        print(status)
    
  4. Fetch User Friends

    user_friends = get_user_friends(handle, key, secret)
    print("\nUser Friends:")
    for friend in user_friends[:2]:
        print(friend)
    
  5. Fetch Problems

    problems, problem_statistics = get_problemset_problems(tags="dp", rating=1900)
    print("\nProblems:")
    for problem in problems[:2]:
        print(problem)
    
  6. Fetch Problem Statistics

    print("\nProblem Statistics:")
    for stat in problem_statistics[:2]:
        print(stat)
    
  7. Fetch Contest Rating Changes

    rating_changes = get_contest_rating_changes(contest_id=566)
    print("\nRating Changes:")
    for change in rating_changes[:2]:
        print(change)
    
  8. Fetch Accepted Submission

    submission_link = get_accepted_submission(handle, contestId=2040, index='C')
    print("\nSubmission Link:")
    print(submission_link)
    

Functions

  • get_user_info(handle): Fetches user information for a given Codeforces handle.
  • get_user_rating(handle): Fetches user rating history.
  • get_user_status(handle, from_index=1, count=10): Fetches user submissions.
  • generate_api_sig(method, params, secret): Generates an API signature for secure requests.
  • get_user_friends(handle, key, secret, only_online=False): Fetches friends list.
  • get_problemset_problems(tags=None, problemset_name=None, rating=None): Fetches problems from the problem set.
  • get_contest_rating_changes(contest_id): Fetches contest rating changes.
  • get_accepted_submission(handle, contestId, index): Fetches a link to an accepted submission.

Limitations

  • The library accesses only public data when the API key is not used.
  • Private data (e.g., hacks during contests) requires a valid API key.
  • The methods are rate-limited by the Codeforces API. Use responsibly.

License

This project is licensed under the MIT License. See the LICENSE file 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

cf_helper-0.1.0.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

cf_helper-0.1.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file cf_helper-0.1.0.tar.gz.

File metadata

  • Download URL: cf_helper-0.1.0.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.2

File hashes

Hashes for cf_helper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e45da65a22d0469a352e30db2ebc9d25777833dcf763545694ed0eb69f7546f3
MD5 5e3329c89b6be553a37f15e484500ff7
BLAKE2b-256 afcf0649a5020f7edd25b4fc670bc76297be95fb3981efc96218815b92ee9777

See more details on using hashes here.

File details

Details for the file cf_helper-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: cf_helper-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.2

File hashes

Hashes for cf_helper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6e8ad97021cd9bce52641b9673e76009253a0fef805b4b02f7bfafa1d1e12913
MD5 f979a895be0205106baeb7e7d408268d
BLAKE2b-256 fc958fc4f83e63dc7a98d13837e41284186908f7b7e39b31afcce958b1dc65e8

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