# Python wrapper for Chess.com Public API
<img src="https://img.shields.io/github/issues/sarartur/chess.com"> <img src="https://img.shields.io/github/forks/sarartur/chess.com"> <img src="https://img.shields.io/github/stars/sarartur/chess.com"> <img src="https://img.shields.io/github/license/sarartur/chess.com"> <img alt="PyPI" src="https://img.shields.io/pypi/v/chess.com"> <img alt="PyPI - Downloads" src="https://img.shields.io/pypi/dm/chess.com?color=007EC6"> <img alt="GitHub Workflow Status (event)" src="https://img.shields.io/github/actions/workflow/status/sarartur/chess.com/build_and_publish.yml">
---
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](https://pypi.org/project/chess.com/): ```pip install chess.com```
## Resources
* Documentation: [readthedocs.org](https://chesscom.readthedocs.io/)
* Published-Data API: [chess.com](https://www.chess.com/news/view/published-data-api)
## 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](https://docs.aiohttp.org/en/stable/) for asynchronous requests and [requests](https://requests.readthedocs.io/en/latest/) for synchronous requests to interact with the API.
#### Synchronous
``` python
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")
player_name = response.json['player']['name']
#or
player_name = response.player.name
```
#### Asynchronous
``` python
import asyncio
from chessdotcom.aio import get_player_profile
usernames = ["fabianocaruana", "GMHikaruOnTwitch", "MagnusCarlsen", "GarryKasparov"]
cors = [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
The package offers several ways to deal with the 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.
``` python
cors = [get_player_profile(name, tts = i / 10) for i, name in enumerate(usernames)]
```
The second method is to adjust the ```rate_limit_handler``` attribute of the `Client` object.
``` python
Client.rate_limit_handler.tries = 2
Client.rate_limit_handler.tts = 4
```
If the initial request gets rate limited the client will automatically retry the request **2 more times** with an interval of **4 seconds**.
#### Configuring Headers
Headers and and other request parameters can be set through the `Client` object. Official Chess.com documentation requires adding a `User-Agent` header.
``` python
from chessdotcom import Client
Client.request_config["headers"]["User-Agent"] = (
"My Python Application. "
"Contact me at email@example.com"
)
```
All the methods from the package will now include the header when making a request to the API.
### Contact
* Email me at <sarartur.ruk@gmail.com> or open a new [Issue](https://github.com/sarartur/chess.com/issues) on Github.
Raw data
{
"_id": null,
"home_page": "https://github.com/sarartur/chess.com",
"name": "chess.com",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": "",
"keywords": "",
"author": "Artur Saradzhyan",
"author_email": "sarartur.ruk@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/2f/a4/c8d0766262b66ea74aa61f3555a1798907d792463097a0b11298f6c616af/chess.com-2.1.0.tar.gz",
"platform": null,
"description": "# Python wrapper for Chess.com Public API\n<img src=\"https://img.shields.io/github/issues/sarartur/chess.com\"> <img src=\"https://img.shields.io/github/forks/sarartur/chess.com\"> <img src=\"https://img.shields.io/github/stars/sarartur/chess.com\"> <img src=\"https://img.shields.io/github/license/sarartur/chess.com\"> <img alt=\"PyPI\" src=\"https://img.shields.io/pypi/v/chess.com\"> <img alt=\"PyPI - Downloads\" src=\"https://img.shields.io/pypi/dm/chess.com?color=007EC6\"> <img alt=\"GitHub Workflow Status (event)\" src=\"https://img.shields.io/github/actions/workflow/status/sarartur/chess.com/build_and_publish.yml\">\n---\nPython 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. \n## Installation \n**The package requires Python 3.7 or higher**.\n\nInstall latest version from [PyPI](https://pypi.org/project/chess.com/): ```pip install chess.com``` \n\n## Resources\n* Documentation: [readthedocs.org](https://chesscom.readthedocs.io/)\n* Published-Data API: [chess.com](https://www.chess.com/news/view/published-data-api)\n\n## Usage\n### Retrieving Data\nAll the functions return a `ChessDotComResponse` object. The data can be accessed in dictionary format or via attributes.\n\nThe package uses [aiohttp](https://docs.aiohttp.org/en/stable/) for asynchronous requests and [requests](https://requests.readthedocs.io/en/latest/) for synchronous requests to interact with the API. \n#### Synchronous\n``` python\nfrom chessdotcom import get_player_profile, Client\n\nClient.request_config[\"headers\"][\"User-Agent\"] = (\n \"My Python Application. \"\n \"Contact me at email@example.com\"\n)\nresponse = get_player_profile(\"fabianocaruana\")\n\nplayer_name = response.json['player']['name']\n#or\nplayer_name = response.player.name\n```\n#### Asynchronous \n``` python \nimport asyncio\n\nfrom chessdotcom.aio import get_player_profile\n\nusernames = [\"fabianocaruana\", \"GMHikaruOnTwitch\", \"MagnusCarlsen\", \"GarryKasparov\"]\n\ncors = [get_player_profile(name) for name in usernames]\n\nasync def gather_cors(cors):\n return await asyncio.gather(*cors)\n\nresponses = asyncio.run(gather_cors(cors))\n\n```\n#### Managing Rate Limit\nThe package offers several ways to deal with the 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.\n\n ``` python \n cors = [get_player_profile(name, tts = i / 10) for i, name in enumerate(usernames)]\n```\nThe second method is to adjust the ```rate_limit_handler``` attribute of the `Client` object.\n\n``` python\nClient.rate_limit_handler.tries = 2\nClient.rate_limit_handler.tts = 4\n```\nIf the initial request gets rate limited the client will automatically retry the request **2 more times** with an interval of **4 seconds**.\n\n#### Configuring Headers\nHeaders and and other request parameters can be set through the `Client` object. Official Chess.com documentation requires adding a `User-Agent` header. \n``` python\nfrom chessdotcom import Client\n\nClient.request_config[\"headers\"][\"User-Agent\"] = (\n \"My Python Application. \"\n \"Contact me at email@example.com\"\n)\n```\nAll the methods from the package will now include the header when making a request to the API.\n\n### Contact\n* Email me at <sarartur.ruk@gmail.com> or open a new [Issue](https://github.com/sarartur/chess.com/issues) on Github.\n\n",
"bugtrack_url": null,
"license": "",
"summary": "Python Wrapper for Chess.com API",
"version": "2.1.0",
"project_urls": {
"Homepage": "https://github.com/sarartur/chess.com"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "a6af66d14cb0645b2c251778ea266497885bcff60201b2fd001cf487e8156567",
"md5": "da4068f824faae6da41ac528d0765587",
"sha256": "4841f905bae02d5caff56c188ae1a0d49701adcbd2bfdbbd0e0a345184dd3ae3"
},
"downloads": -1,
"filename": "chess.com-2.1.0-py3-none-any.whl",
"has_sig": false,
"md5_digest": "da4068f824faae6da41ac528d0765587",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 11571,
"upload_time": "2023-09-20T02:18:58",
"upload_time_iso_8601": "2023-09-20T02:18:58.982560Z",
"url": "https://files.pythonhosted.org/packages/a6/af/66d14cb0645b2c251778ea266497885bcff60201b2fd001cf487e8156567/chess.com-2.1.0-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "2fa4c8d0766262b66ea74aa61f3555a1798907d792463097a0b11298f6c616af",
"md5": "c19670b5aaec4ae90ae56f184c9f3c10",
"sha256": "a8ce5b3c74ac31b6b3a4891af3c8ed77e3c2cdf9c7df92eda88a7d3786f2a53a"
},
"downloads": -1,
"filename": "chess.com-2.1.0.tar.gz",
"has_sig": false,
"md5_digest": "c19670b5aaec4ae90ae56f184c9f3c10",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 9585,
"upload_time": "2023-09-20T02:19:00",
"upload_time_iso_8601": "2023-09-20T02:19:00.291489Z",
"url": "https://files.pythonhosted.org/packages/2f/a4/c8d0766262b66ea74aa61f3555a1798907d792463097a0b11298f6c616af/chess.com-2.1.0.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-09-20 02:19:00",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "sarartur",
"github_project": "chess.com",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [],
"lcname": "chess.com"
}