nav-chess-com


Namenav-chess-com JSON
Version 2.2.0 PyPI version JSON
download
home_pageNone
SummaryPython Wrapper for Chess.com API
upload_time2024-08-18 10:56:26
maintainerNone
docs_urlNone
authorArtur Saradzhyan
requires_python<4.0,>=3.9
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python wrapper for Chess.com Public API

> Maintained Fork

[![Github Issues](https://img.shields.io/github/issues/sarartur/chess.com)](https://github.com/sarartur/chess.com/issues)
[![GitHub Forks](https://img.shields.io/github/forks/sarartur/chess.com)](https://github.com/sarartur/chess.com/forks)
[![Github Stars](https://img.shields.io/github/stars/sarartur/chess.com)](https://github.com/sarartur/chess.com/stargazers)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![PyPI - Version](https://img.shields.io/pypi/v/chess.com)](https://pypi.org/project/chess.com/)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/chess.com?color=007EC6)](https://pypi.org/project/chess.com/)
[![Python package](https://github.com/Naviamold1/chess.com/actions/workflows/python-package.yml/badge.svg)](https://github.com/Naviamold1/chess.com/actions/workflows/python-package.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.9 or higher**.

Install latest version from [PyPI](https://pypi.org/project/chess.com/):

```py
pip install nav-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

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

### 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**.

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": null,
    "name": "nav-chess-com",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.9",
    "maintainer_email": null,
    "keywords": null,
    "author": "Artur Saradzhyan",
    "author_email": "sarartur.ruk@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/9f/9c/de2f5ab6201f61504245c611fff60792f5047ccb85076cb848088b524520/nav_chess_com-2.2.0.tar.gz",
    "platform": null,
    "description": "# Python wrapper for Chess.com Public API\n\n> Maintained Fork\n\n[![Github Issues](https://img.shields.io/github/issues/sarartur/chess.com)](https://github.com/sarartur/chess.com/issues)\n[![GitHub Forks](https://img.shields.io/github/forks/sarartur/chess.com)](https://github.com/sarartur/chess.com/forks)\n[![Github Stars](https://img.shields.io/github/stars/sarartur/chess.com)](https://github.com/sarartur/chess.com/stargazers)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n[![PyPI - Version](https://img.shields.io/pypi/v/chess.com)](https://pypi.org/project/chess.com/)\n[![PyPI - Downloads](https://img.shields.io/pypi/dm/chess.com?color=007EC6)](https://pypi.org/project/chess.com/)\n[![Python package](https://github.com/Naviamold1/chess.com/actions/workflows/python-package.yml/badge.svg)](https://github.com/Naviamold1/chess.com/actions/workflows/python-package.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\n## Installation\n\n**The package requires Python 3.9 or higher**.\n\nInstall latest version from [PyPI](https://pypi.org/project/chess.com/):\n\n```py\npip install nav-chess.com\n```\n\n## Resources\n\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\n### Configuring Headers\n\nHeaders and and other request parameters can be set through the `Client` object. Official Chess.com documentation requires adding a `User-Agent` header.\n\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```\n\n### Retrieving Data\n\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\n#### Synchronous\n\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\n#### Asynchronous\n\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\n#### Managing Rate Limit\n\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\ncors = [get_player_profile(name, tts = i / 10) for i, name in enumerate(usernames)]\n```\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```\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\nAll the methods from the package will now include the header when making a request to the API.\n\n### Contact\n\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": "MIT",
    "summary": "Python Wrapper for Chess.com API",
    "version": "2.2.0",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "182ab6b99ff1d4f4512b38e3ca385770a12f468dd09d4966a9f958c985158da6",
                "md5": "5421ac549d8f413104baf7f4913ffcd0",
                "sha256": "d6697c6832207091584e512ceb26509def7170367463eb9f541665c0322d1e8e"
            },
            "downloads": -1,
            "filename": "nav_chess_com-2.2.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5421ac549d8f413104baf7f4913ffcd0",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.9",
            "size": 8955,
            "upload_time": "2024-08-18T10:56:25",
            "upload_time_iso_8601": "2024-08-18T10:56:25.132258Z",
            "url": "https://files.pythonhosted.org/packages/18/2a/b6b99ff1d4f4512b38e3ca385770a12f468dd09d4966a9f958c985158da6/nav_chess_com-2.2.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9f9cde2f5ab6201f61504245c611fff60792f5047ccb85076cb848088b524520",
                "md5": "685d1f729f44e1c9c224dfdee57d33b5",
                "sha256": "df98a62d1cd8246ab2ec56fffcaffb0cf0687b02533056950d9708782823a5cf"
            },
            "downloads": -1,
            "filename": "nav_chess_com-2.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "685d1f729f44e1c9c224dfdee57d33b5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.9",
            "size": 8728,
            "upload_time": "2024-08-18T10:56:26",
            "upload_time_iso_8601": "2024-08-18T10:56:26.645928Z",
            "url": "https://files.pythonhosted.org/packages/9f/9c/de2f5ab6201f61504245c611fff60792f5047ccb85076cb848088b524520/nav_chess_com-2.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-08-18 10:56:26",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "nav-chess-com"
}
        
Elapsed time: 0.40398s