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:
- Go to Codeforces: Visit https://codeforces.com/settings/api.
- 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.
- Store the Key and Secret:
- Add your
keyandsecretto an environment variable file (e.g.,.env):key="your_api_key" secret="your_api_secret"
- Add your
Usage
-
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"
-
Fetch User Information
user_info = get_user_info(handle) print("\nUser Info:") print(user_info)
-
Fetch User Status
user_status = get_user_status(handle) print("\nUser Status:") for status in user_status[:2]: print(status)
-
Fetch User Friends
user_friends = get_user_friends(handle, key, secret) print("\nUser Friends:") for friend in user_friends[:2]: print(friend)
-
Fetch Problems
problems, problem_statistics = get_problemset_problems(tags="dp", rating=1900) print("\nProblems:") for problem in problems[:2]: print(problem)
-
Fetch Problem Statistics
print("\nProblem Statistics:") for stat in problem_statistics[:2]: print(stat)
-
Fetch Contest Rating Changes
rating_changes = get_contest_rating_changes(contest_id=566) print("\nRating Changes:") for change in rating_changes[:2]: print(change)
-
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file cf-helper-0.1.2.tar.gz.
File metadata
- Download URL: cf-helper-0.1.2.tar.gz
- Upload date:
- Size: 4.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e2fa019af5e139f4a69fe4ecad2b3535004e018cf46fd409fe18a54487f0f948
|
|
| MD5 |
394ee0c213ccf930ee2da01fb62ad74e
|
|
| BLAKE2b-256 |
bfecf1137cd5dceb8015a2b3bda4252042534f52ee3b10e10b4e904bf462fc37
|
File details
Details for the file cf_helper-0.1.2-py3-none-any.whl.
File metadata
- Download URL: cf_helper-0.1.2-py3-none-any.whl
- Upload date:
- Size: 5.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.11.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
de4e762fe96c3babbfdf5008e9f2359107691b9b2294ca92dc17695326dbf27e
|
|
| MD5 |
15c75e8bb66dfcab6d4cd339142c8a09
|
|
| BLAKE2b-256 |
c5dbe9aecf5536cbcdc03592db2da479ae79a8f13808c3ff1181a61532ab5484
|