Skip to main content

A client for the lichess.org API

Project description

This is a client library for the lichess.org API. It is designed to be:

  • Easy to use
  • Customizable when you need it
  • Adaptable to API changes
  • Easy to integrate with python-chess

Have a look at some short examples. For more, check out the full documentation.

Getting a user’s rating:

>>> import lichess.api
>>>
>>> user = lichess.api.user('thibault')
>>> print(user['perfs']['blitz']['rating'])
1617

Checking who’s online and playing:

>>> import lichess.api
>>>
>>> users = list(lichess.api.users_status(['thibault', 'cyanfish']))
>>> online = [u['id'] for u in users if u['online']]
>>> playing = [u['id'] for u in users if u['playing']]
>>> print(online, playing)
['thibault', 'cyanfish'] ['cyanfish']

Saving a PGN of a user’s last 200 games:

>>> import lichess.api
>>> import lichess.pgn
>>> import itertools
>>>
>>> games = lichess.api.user_games('thibault', with_moves=1)
>>> last_200 = itertools.islice(games, 200)
>>> lichess.pgn.save_games(last_200, 'last200.pgn')

Integrating with python-chess:

>>> import lichess.api
>>> import lichess.pgn
>>> import chess.pgn
>>>
>>> api_game = lichess.api.game('Qa7FJNk2', with_moves=1)
>>> game = chess.pgn.read_game(lichess.pgn.io_from_game(api_game))
>>> print(game.end().board())
. . k . R b r .
. p p r . N p .
p . . . . . . p
. . . . . . . .
. . . p . . . .
P . . P . . . P
. P P . . P P .
. . K R . . . .

Installing

pip install python-lichess

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for python-lichess, version 0.5
Filename, size File type Python version Upload date Hashes
Filename, size python_lichess-0.5-py2.py3-none-any.whl (8.7 kB) File type Wheel Python version py2.py3 Upload date Hashes View
Filename, size python-lichess-0.5.tar.gz (6.2 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page