Python Lichess API
Project description
lichess: a Python wrapper for the Lichess API
lichess is a Python library for interacting with the Lichess API and can be used to get profile data, game data, and much more.
This project is still in Pre-Alpha. As a result, it is still unstable and not all features have been implemented.
Install
You can install lichess on the Terminal (macOS/UNIX) or the Command Prompt (Windows) with:
pip install lichess
Alternatively, you can use Git to clone the repository from GitHub with:
git clone https://github.com/qe/lichess.git cd lichess pip install .
Or, if you already have it, upgrade to the latest version with:
pip install lichess --upgrade
Example
For the full documentation, please check the Lichess Python API Documentation.
Some methods, such as Client.get_email(), require authorization while others, such as Client.get_leaderboard(), do not require it. As a result, if you want to use a method/endpoint that does require authorization, you will need to generate a personal access token on Lichess. If you do so, this will be your API Key.
To determine whether or nor you need to generate a personal access token, check the Lichess API Documentation if the endpoint your interested in using has a OAuth2 badge.
Here’s an example of using lichess with an personal access token:
API_KEY = "<YOUR API KEY GOES HERE>" myclient = Client(token=API_KEY) print(myclient.get_email())
{'email': 'youremailwillshowuphere@gmail.com'}
Here’s an example of using lichess without a personal access token:
from lichess import myclient = Client() print(myclient.get_data("ismodes"))
{ "id": "ismodes", "username": "ismodes", "perfs": { "blitz": {"games": 90, "rating": 1599, "rd": 109, "prog": 21}, "puzzle": {"games": 984, "rating": 2355, "rd": 132, "prog": 0, "prov": True}, "bullet": {"games": 0, "rating": 1500, "rd": 500, "prog": 0, "prov": True}, "correspondence": { "games": 0, "rating": 1500, "rd": 500, "prog": 0, "prov": True, }, "classical": {"games": 0, "rating": 1500, "rd": 500, "prog": 0, "prov": True}, "rapid": {"games": 239, "rating": 1909, "rd": 102, "prog": -79}, "storm": {"runs": 15, "score": 24}, "racer": {"runs": 2, "score": 32}, }, "createdAt": 1620502920988, "online": True, "profile": { "country": "AR", "location": "🇦🇷", "bio": "🇦🇷", "firstName": "Velez", "links": "🇦🇷", }, "seenAt": 1647342929853, "playTime": {"total": 208321, "tv": 0}, "url": "https://lichess.org/@/ismodes", "completionRate": 73, "count": { "all": 338, "rated": 329, "ai": 0, "draw": 13, "drawH": 13, "loss": 148, "lossH": 148, "win": 177, "winH": 177, "bookmark": 2, "playing": 0, "import": 0, "me": 0, }, }
For more examples, check the examples directory in the source code.
Warnings
Make sure your inputs are valid.
There is basic error handling for some invalid inputs, but there are exceptions.
Firstly, there are many types of invalid inputs. Here is an example:
- Usernames that don’t exist
Valid username, but no user has taken it
Invalid username
lichess does basic error handling with invalid inputs (using Regex), but it does not account for valid inputs that do not exist. Here’s a more explicit example:
"jzq0wUnCYR" is a valid username (i.e. it can be registered), but at the time of writing this, there is no user by this name. As a result, the following code does not return everything:
from lichess import get_status myclient = Client() print(myclient.get_status("jzq0wUnCYR", "penguingim1"))
[{'name': 'penguingim1', 'title': 'GM', 'patron': True, 'id': 'penguingim1'}]
Conversely, "jzq0 wUnCYR" is an invalid username, since it has invalid characters (note the whitespace!) However, lichess does catch this error, as seen below:
from lichess import get_status myclient = Client() print(myclient.get_status("jzq0 wUnCYR", "penguingim1"))
Traceback (most recent call last): File "main.py", line 109, in <module> main() File "main.py", line 76, in main print(myclient.get_status("jzq0 wUnCYR", "penguingim1")) raise ArgumentValueError("One or more usernames are invalid.") lichess.exceptions.ArgumentValueError: One or more usernames are invalid.
It is your responsibility to make sure your inputs are valid, but lichess tries its best to catch errors <3
Links
Contact
Email me at
helloemailmerighthere [at] gmail [dot] com
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 lichess-0.1.5.tar.gz
.
File metadata
- Download URL: lichess-0.1.5.tar.gz
- Upload date:
- Size: 10.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 11dff8d52195a2ea23f49002c52f0c02d491de82a28932cc3e238fb5d584e40f |
|
MD5 | 44a4d3a03d1549a2f2db2204bc70defa |
|
BLAKE2b-256 | 7e5de6cdb31f7ff8284cdb647fc0642e97dca3824eb9bf22ac024d977cd2dce1 |
File details
Details for the file lichess-0.1.5-py3-none-any.whl
.
File metadata
- Download URL: lichess-0.1.5-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.7.1 importlib_metadata/4.10.1 pkginfo/1.8.2 requests/2.27.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6c5aadeffbb3499c535539d0501caa68c5fbcca9ac9f483db9f5cf61692b43d8 |
|
MD5 | 7906b55fa634280b5fedff3d6fe29974 |
|
BLAKE2b-256 | c833164db8bb2a1a6c454a2775779e25e6da4612587670522dd98e3fbb942152 |