Skip to main content

Chess.com API Client

PyPI version Python versions Documentation Status GitHub Actions Coverage License: MIT

A modern, fully typed, asynchronous Python wrapper for the Chess.com API.

Features

  • 🚀 Fully Async: Built with aiohttp for high-performance async operations
  • 📦 Type Safety: Complete type hints and runtime type checking
  • 🛡️ Robust Error Handling: Comprehensive error types and automatic retries
  • 🔄 Rate Limiting: Built-in rate limit handling with smart backoff
  • 📚 Rich Data Models: Intuitive object-oriented interface to API data
  • ✨ Modern Python: Supports Python 3.8+
  • 📈 Production Ready: Thoroughly tested and production hardened

Installation

pip install chess-com-api

Quick Start

import asyncio
from chess_com_api import ChessComClient

async def main():
    async with ChessComClient() as client:
        # Get player profile
        player = await client.get_player("hikaru")
        print(f"Title: {player.title}")
        print(f"Rating: {player.rating}")
        
        # Get recent games
        games = await client.get_player_current_games("hikaru")
        for game in games:
            print(f"Game URL: {game.url}")
            print(f"Time Control: {game.time_control}")

asyncio.run(main())

Advanced Usage

Custom Session Configuration

import aiohttp
from chess_com_api import ChessComClient

async def main():
    # Configure custom timeout and headers
    timeout = aiohttp.ClientTimeout(total=60)
    session = aiohttp.ClientSession(
        timeout=timeout,
        headers={"User-Agent": "MyApp/1.0"}
    )
    
    client = ChessComClient(
        session=session,
        max_retries=5,
        rate_limit=100
    )
    
    try:
        # Your code here
        pass
    finally:
        await client.close()

asyncio.run(main())

Error Handling

from chess_com_api.exceptions import NotFoundError, RateLimitError

async def get_player_info(username: str):
    try:
        async with ChessComClient() as client:
            player = await client.get_player(username)
            return player
    except NotFoundError:
        print(f"Player {username} not found")
    except RateLimitError:
        print("Rate limit exceeded, please try again later")
    except Exception as e:
        print(f"An error occurred: {e}")

Documentation

For full documentation, please visit chess-com-api.readthedocs.io.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request. For major changes, please open an issue first to discuss what you would like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Install development dependencies (pip install -e ".[dev]")
  4. Make your changes
  5. Run tests (pytest)
  6. Commit your changes (git commit -m 'Add some AmazingFeature')
  7. Push to the branch (git push origin feature/AmazingFeature)
  8. Open a Pull Request

Please make sure to update tests as appropriate and follow the existing code style.

License

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

Acknowledgments

  • Chess.com for providing the public API
  • The Python community for valuable feedback and contributions

Support

If you encounter any problems or have any questions, please open an issue on GitHub.

Metadata

Release files for chess-com-api 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chess-com-api 1.1.0
File Size Uploaded
chess_com_api-1.1.0.tar.gz 85.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chess-com-api 1.1.0
File Interpreter ABI Platform
chess_com_api-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 115.8 kB

Release files / chess_com_api-1.1.0.tar.gz

Download URL chess_com_api-1.1.0.tar.gz
Size 85.6 kB
Tags Source
SHA-256 checksum
How to use checksums
b721713857537eba710cf9f1e097b7884c54089f7b3cf0db8380883719fb1b7c
BLAKE2b-256 checksum
How to use checksums
ba6eeed3699fe12438d8ee077d7219bf1a5097b984bfe63a3806e8c1e99bccbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2024.

Transparency log

Release files / chess_com_api-1.1.0-py3-none-any.whl

Download URL chess_com_api-1.1.0-py3-none-any.whl
Size 30.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2bc7fc22c80c3c16edbf3d87f98aaa06ada32f792229ea501742816c802b40bf
BLAKE2b-256 checksum
How to use checksums
2b9166919fdf0dc019201de15645cc3f69f8c45e3744a02b3abd17d76c80e1ce
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/5.1.1 CPython/3.12.7

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 23, 2024.

Transparency log

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page