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.1.tar.gz (4.3 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.1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file cf-helper-0.1.1.tar.gz.

File metadata

  • Download URL: cf-helper-0.1.1.tar.gz
  • Upload date:
  • Size: 4.3 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.1.tar.gz
Algorithm Hash digest
SHA256 d34411e8de1a2e1e74610e508036832dc96036ecb62e6b8e1a7fa97b735ba60f
MD5 32b9c2a78a0679de93fce37da023f77c
BLAKE2b-256 529e519e8955e0bf624b49942898d869690d37b9f606045fc6ecffcee7465f6c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: cf_helper-0.1.1-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.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ec0e441fdc43b00a2f1514cfa08d19e8b68c7d257ec2593227abf7750247effd
MD5 7c15c2f9f87e861cf453c2271bd87bf5
BLAKE2b-256 514e238b665ba131852a428e0b804596b7022699b4a7655e561fa786bea9f6ea

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