An async Python wrapper for the Chess.com API
Project description
Chess.com API Client
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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature
) - Install development dependencies (
pip install -e ".[dev]"
) - Make your changes
- Run tests (
pytest
) - Commit your changes (
git commit -m 'Add some AmazingFeature'
) - Push to the branch (
git push origin feature/AmazingFeature
) - 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.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file chess_com_api-1.0.0.tar.gz
.
File metadata
- Download URL: chess_com_api-1.0.0.tar.gz
- Upload date:
- Size: 85.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c161184f96c04f65c751f4db2ca4d996ba875e9caec440eb52803f60cb7b3f0 |
|
MD5 | 42b694aa8eb8e8f0bff0833a5a519fed |
|
BLAKE2b-256 | 64ae9d640ef91d9abfdeb51b14457073f688a204b76d0a10c9e3fe1249e0a541 |
Provenance
The following attestation bundles were made for chess_com_api-1.0.0.tar.gz
:
Publisher:
publish.yml
on Stupidoodle/chess-com-api
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
chess_com_api-1.0.0.tar.gz
- Subject digest:
6c161184f96c04f65c751f4db2ca4d996ba875e9caec440eb52803f60cb7b3f0
- Sigstore transparency entry: 151040039
- Sigstore integration time:
- Predicate type:
File details
Details for the file chess_com_api-1.0.0-py3-none-any.whl
.
File metadata
- Download URL: chess_com_api-1.0.0-py3-none-any.whl
- Upload date:
- Size: 30.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a00dcd6ef449e0cf549eb8d09951527ef2c02dc94013770db9986500a6723174 |
|
MD5 | d03ce82819d2dd23494e1269784095fc |
|
BLAKE2b-256 | 41d59b2b6a37bf8d1b6b339b69cddd870cf1e362160955ac124dfc9b4cdcb07c |
Provenance
The following attestation bundles were made for chess_com_api-1.0.0-py3-none-any.whl
:
Publisher:
publish.yml
on Stupidoodle/chess-com-api
-
Statement type:
https://in-toto.io/Statement/v1
- Predicate type:
https://docs.pypi.org/attestations/publish/v1
- Subject name:
chess_com_api-1.0.0-py3-none-any.whl
- Subject digest:
a00dcd6ef449e0cf549eb8d09951527ef2c02dc94013770db9986500a6723174
- Sigstore transparency entry: 151040040
- Sigstore integration time:
- Predicate type: