Python Wrapper for Chess.com API
Project description
Python wrapper for Chess.com Public API
Python wrapper for Chess.com API which provides public data from the chess.com website. All endpoints provided by Chess.com's API are available in the respectively named methods.
Installation
The package requires Python 3.7 or higher.
Install latest version from PyPI: pip install chess.com
Resources
- Documentation: readthedocs.org
- Published-Data API: chess.com
Usage
Retrieving Data
All the functions return a ChessDotComResponse
object. The data can be accessed in dictionary format or via attributes.
The package uses aiohttp for asynchronous requests and requests for synchronous requests to interact with the API.
Using client instance
from chessdotcom import ChessDotComClient
client = ChessDotComClient(user_agent = "My Python Application...")
response = client.get_player_profile("fabianocaruana")
player_name = response.json['player']['name']
#or
player_name = response.player.name
Using functions
from chessdotcom import get_player_profile, Client
Client.request_config["headers"]["User-Agent"] = (
"My Python Application. "
"Contact me at email@example.com"
)
response = get_player_profile("fabianocaruana")
Asynchronous
from chessdotcom import ChessDotComClient
client = ChessDotComClient(user_agent = "My Python Application...", aio = True)
usernames = ["fabianocaruana", "GMHikaruOnTwitch", "MagnusCarlsen", "GarryKasparov"]
cors = [client.get_player_profile(name) for name in usernames]
async def gather_cors(cors):
return await asyncio.gather(*cors)
responses = asyncio.run(gather_cors(cors))
Managing Rate Limit
Every function accepts a tts
parameter which controls the number of seconds the Client
will wait before making the request. This is useful if running a lot of coroutines at once.
cors = [get_player_profile(name, tts = i / 10) for i, name in enumerate(usernames)]
The second method is to pass rate_limit_handler
option to the client.
from chessdotcom import RateLimitHandler
client = ChessDotComClient(
rate_limit_handler = RateLimitHandler(tts = 4,retries = 2)
)
If the initial request gets rate limited the client will automatically retry the request 2 more times with an interval of 4 seconds.
Contact
- Open a new 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
Hashes for chess.com-3.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c00ad7dbd44f870a8d98c8ceed0f40d3c51cd16d7a5a675995b51da962bd3ae4 |
|
MD5 | 00505c5587d4db53b59472eb088edc3f |
|
BLAKE2b-256 | ecb9712d16c1f43301610363b95cbe165b28167e12a12f6806beac7339c84899 |