Skip to main content

Python wrapper for the Lichess API

Project description

Logo

lichess: a Python wrapper for the Lichess API

License PyPI GitHub Repo Size GitHub Code Size (bytes) Total Lines of Code

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.


Installation

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 -U

Usage

This GitHub Gist shows the currently available methods since the full documentation is still in development.

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 if the endpoint you are interested in using has a OAuth2 badge in the Lichess API Documentation.

Here is an example of using lichess without a personal access token:

import lichess

myclient = lichess.Client()

Here is an example of using lichess with a personal access token:

import lichess

API_KEY = "<YOUR API KEY GOES HERE>"
myclient = lichess.Client(token=API_KEY)

Quick Examples

The following are some examples of popular uses of this package:


Get the profile data of a user

myclient = lichess.Client()

user = myclient.get_data("bmartin")

Get the rating history of a user

myclient = lichess.Client()

history = myclient.get_rating_history("agadmator")

Get the list of users that are offline, online, and playing

myclient = lichess.Client()

users = ["Oliver_Penrose", "bmartin", "ismodes", "penguingim1", "Zhigalko_Sergei"]
data = myclient.get_status(users)

offline = [i['name'] for i in data if 'online' not in i.keys()]
online = [i['name'] for i in data if 'online' in i.keys()]
playing = [i['name'] for i in data if 'playing' in i.keys()]

Download all the games of a user

myclient = lichess.Client()

games = myclient.export_by_user(<USERNAME GOES HERE>)

with open("games.pgn", "w") as f:
    f.write(games)
f.close()

Get the list of all the members of a team

API_KEY = "<YOUR API KEY GOES HERE>"
myclient = lichess.Client(token=API_KEY)

members = myclient.get_team_members(<TEAMNAME GOES HERE>)

Get the list of all the IDs of the puzzles you have failed

API_KEY = "<YOUR API KEY GOES HERE>"
myclient = lichess.Client(token=API_KEY)

activity = myclient.get_puzzle_activity()
failed = [i['id'] for i in activity if not i['win']]

For more examples, check the examples directory in the source code.


Endpoints

This GitHub Gist shows the current available methods


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

lichess-0.2.4.tar.gz (13.0 kB view details)

Uploaded Source

Built Distribution

lichess-0.2.4-py3-none-any.whl (11.7 kB view details)

Uploaded Python 3

File details

Details for the file lichess-0.2.4.tar.gz.

File metadata

  • Download URL: lichess-0.2.4.tar.gz
  • Upload date:
  • Size: 13.0 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

Hashes for lichess-0.2.4.tar.gz
Algorithm Hash digest
SHA256 2708fceb1512cd14d8d8bbdd668166884dc7f90d4aa70ba863e0ec272678bdf1
MD5 850b39efbc437cbfe38fe6e9256bf770
BLAKE2b-256 8366f3147fce2319c5e57befc977d23f19f940a8286b47ef4f44245b2ff1946e

See more details on using hashes here.

File details

Details for the file lichess-0.2.4-py3-none-any.whl.

File metadata

  • Download URL: lichess-0.2.4-py3-none-any.whl
  • Upload date:
  • Size: 11.7 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

Hashes for lichess-0.2.4-py3-none-any.whl
Algorithm Hash digest
SHA256 5f54b98c946978468908b1a7836816cfc29be256f2051470409146effe6832cf
MD5 170798d84ee5db8be2ab7647b2b71ebb
BLAKE2b-256 88805d54099a9b53d4a5f3f8bf7c636db6688a0abc261c20f845ae772fac8a1d

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 Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page