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

Faster | Better | Type-Safe

Passing Package
Type Checking

codeforcespy Logo

Overview

codeforcespy is a high-performance, type-safe Python library that simplifies interacting with the Codeforces API. It provides both synchronous and asynchronous client handlers to suit different application needs, ensuring that your code remains efficient, reliable, and fully type-checked.

Built entirely based on the official Codeforces API Documentation, codeforcespy adheres to industry best practices, offering a consistent API surface regardless of your chosen client mode.

Table of Contents

Features

  • Dual Client Handlers:
    Choose between a synchronous handler (SyncMethod) or an asynchronous handler (AsyncMethod) based on your application requirements.

  • Type-Safe:
    Leverages static type checking to ensure reliable and maintainable code.

  • Authentication Support:
    Easily enable authentication by passing the enable_auth parameter to the client constructor to access user-specific endpoints.

  • Modular and Extensible:
    Customize types using the provided abc module for a tailored experience.

  • Optimized Serialization:
    Utilizes msgspec for fast data validation and serialization.

  • Code Quality:
    Enforced by ruff for consistent formatting and adherence to best practices.

Installation

As a User

Install codeforcespy via pip:

pip install codeforcespy

As a Developer

For development, install with the extra dependencies:

pip install codeforcespy[dev]

Quick Start

Asynchronous Usage

Below is a basic example demonstrating how to retrieve user information asynchronously:

import asyncio
import pycodeforces

async def main():
    # Initialize the asynchronous client
    api = pycodeforces.AsyncMethod()
    
    # Retrieve user information for multiple handles separated by semicolons
    users = await api.get_user(handles="DmitriyH;Fefer_Ivan")
    
    # Process and print the avatar for each user
    for user in users:
        print(user.avatar)

    # Close the client connection
    await api.close()

asyncio.run(main())

Synchronous Usage

The synchronous client offers similar functionality:

import pycodeforces

def main():
    # Initialize the synchronous client
    api = pycodeforces.SyncMethod()
    
    # Retrieve user information for multiple handles separated by semicolons
    users = api.get_user(handles="DmitriyH;Fefer_Ivan")
    
    # Process and print the avatar for each user
    for user in users:
        print(user.avatar)
    
    # Close the client connection
    api.close()

if __name__ == "__main__":
    main()

Customization and Advanced Usage

  • Authentication:
    To enable authentication for endpoints that require it, simply pass enable_auth=True along with your API key and secret during client initialization.

  • Type Customization:
    If you need to customize or extend the data models, refer to the abc module which contains the abstract classes and objects used throughout the library.

  • Consistent API Surface:
    Both client types provide the same set of methods, ensuring that you can switch between asynchronous and synchronous programming with minimal changes.

Contributing

Contributions are welcome! If you’d like to contribute:

  • Please review the Issues to see where you can help.
  • Ensure that your changes maintain strict type-checking and adhere to the established coding guidelines.
  • Submit a pull request against the production branch.

License

This project is licensed under the MIT License. See the LICENSE file for details.


Thank you for checking out codeforcespy. If you find it useful, please give it a star!

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.0.tar.gz (16.2 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.0-py3-none-any.whl (15.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: codeforcespy-1.0.tar.gz
  • Upload date:
  • Size: 16.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for codeforcespy-1.0.tar.gz
Algorithm Hash digest
SHA256 a234b97c1e0a889acfdb5ddbc9caff865c388e3af06acaa70bcd824146122669
MD5 cedc3896f664e769fcf981f8c579f0e8
BLAKE2b-256 e6ad4bf2ef5096517e5dbf920f7ac5ea8f121c74fbd1347b6d2ba7c06c77e2c0

See more details on using hashes here.

File details

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

File metadata

  • Download URL: codeforcespy-1.0-py3-none-any.whl
  • Upload date:
  • Size: 15.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.21

File hashes

Hashes for codeforcespy-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 7ca4936bcef0ec7fec2abe91e2015485f4361293646f0dbf95a5c78ca84554dc
MD5 aef6c0306ba78f8488994a8800e8560f
BLAKE2b-256 fccbe802a30e5c86bc252f90e237aa024ac797ca8262f45a6b89744903577b57

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