Skip to main content

Python Wrapper for Chess.com API

Project description

Python wrapper for Chess.com Public API

GitHub Workflow Status (event) PyPI PyPI - Downloads

Python wrapper for Chess.com API which provides public data from the chess.com website.

Installation

The package requires Python 3.8 or higher.

Install latest version from PyPI pip install chess.com

Resources

Usage

Retrieving Data

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")

response.player.name # 'Fabiano Caruana'
response.player.title # 'GM'
response.player.last_online_datetime # datetime.datetime(2024, 10, 25, 20, 8, 28)
response.player.joined_datetime # datetime.datetime(2013, 3, 17, 15, 14, 32)
# See readthedocs for full documentation of responses

# or access the source
response.json['player']['name'] # 'Fabiano Caruana'

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.

Available Endpoints

Player Data

Clubs

Tournaments

Team Matches

Countries

Daily Puzzle

Other

Reporting Issues

Chess.com API is subject to change. Smoke tests are ran daily to make sure the package is working correctly.

Please open an Issue if you spot any bugs.

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

chess_com-3.11.0.tar.gz (23.0 kB view details)

Uploaded Source

Built Distribution

chess.com-3.11.0-py3-none-any.whl (48.0 kB view details)

Uploaded Python 3

File details

Details for the file chess_com-3.11.0.tar.gz.

File metadata

  • Download URL: chess_com-3.11.0.tar.gz
  • Upload date:
  • Size: 23.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for chess_com-3.11.0.tar.gz
Algorithm Hash digest
SHA256 079ce8e1a67dfa5e1c17eeeb850c45481992cb5d0e8cccb107496868cd0bdc4d
MD5 0e884b710080edcd82219e8ccc5bead0
BLAKE2b-256 0fc2641c81964f6421a5cfc662775cc32d4860bbaecb217e050193ebda69a600

See more details on using hashes here.

File details

Details for the file chess.com-3.11.0-py3-none-any.whl.

File metadata

  • Download URL: chess.com-3.11.0-py3-none-any.whl
  • Upload date:
  • Size: 48.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.11.11

File hashes

Hashes for chess.com-3.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b39018a69be403b36a262896d40ad276e10736c8a10e3df3eb291ff6a75928c1
MD5 2995416b0686db357d1a1e33b47d9c66
BLAKE2b-256 71603d65d6325796038557523b67c512ee648d60097b1758b5a6e83238d894cd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page