Skip to main content

chess_export

PyPi version Python 3.7|3.8|3.9|3.10 PRs Welcome

Export your (or someone else's) chess.com/lichess.org games using their APIs

  • Chess.com requires no authentication, see their public API docs
  • Lichess requires you to create a token, you can do so by going here (this requires no extra scopes)

Installation

Requires python3.8+

To install with pip, run:

pip install chess-export

Usage

Each subcommand (chessdotcom/lichess) has an export and inspect command -- export prints data about your games as JSON, inspect reads that dumped info so you can use it in the REPL.

The inspect command just accepts the file as the first argument, like chess_export lichess inspect data.json or chess_export chessdotcom inspect data.json

chessdotcom export

The only required argument is your username, the API serves public data and has no serial rate limit

$ chess_export chessdotcom export seanbreckenridge >data.json
Requesting https://api.chess.com/pub/player/seanbreckenridge/games/archives
Requesting https://api.chess.com/pub/player/seanbreckenridge/games/2021/01
...

If you're getting 403 errors, you may have to supply a user agent with your email, see this forum thread

TO do that, you can pass the --user-agent-email flag or set the CHESSDOTCOM_USER_AGENT_EMAIL environment variable.

lichess export

Requires your username and a token (this requires no extra scopes). The token can be provided with the --token flag or by setting the LICHESS_TOKEN environment variable.

$ chess_export lichess export seanbreckenridge > data.json
Requesting https://lichess.org/api/games/user/seanbreckenridge?pgnInJson=true

Example

The games are described in PGN (which can be parsed using the chess package)

$ chess_export chessdotcom export seanbreckenridge >data.json
Requesting https://api.chess.com/pub/player/seanbreckenridge/games/archives
Requesting https://api.chess.com/pub/player/seanbreckenridge/games/2021/01
Requesting https://api.chess.com/pub/player/seanbreckenridge/games/2021/02
$ chess_export chessdotcom inspect data.json

In [1]: import io, chess.pgn

In [2]: game = chess.pgn.read_game(io.StringIO(games[0].pgn))

In [3]: for move in game.mainline_moves():
   ...:     print(move)
   ...:
e2e4
e7e6
b1c3
d8f6
d2d3
f8c5
d3d4
c5d4
f2f3

The information returned by chess.com/lichess are slightly different, see the lichess/model.py and chessdotcom/model.py files for reference

Tests

git clone 'https://github.com/seanbreckenridge/chess_export'
cd ./chess_export
pip install '.[testing]'
mypy ./chess_export

Release files for chess-export 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for chess-export 0.1.1
File Size Uploaded
chess_export-0.1.1.tar.gz 8.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chess-export 0.1.1
File Interpreter ABI Platform
chess_export-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 17.9 kB

Release files / chess_export-0.1.1.tar.gz

Download URL chess_export-0.1.1.tar.gz
Size 8.5 kB
Tags Source
SHA-256 checksum
How to use checksums
f366d8df7e0a7842f13479c8a2ef5cfe4a13f7113394c6f5c7cd9f2dfa32134f
BLAKE2b-256 checksum
How to use checksums
f993c217d622d5654dbf5ebab31b107c26268dfbad8ea50b27afd607621e0360
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release files / chess_export-0.1.1-py3-none-any.whl

Download URL chess_export-0.1.1-py3-none-any.whl
Size 9.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
32c2b4604dbb836ea2d91f1e4b2a24899765b0df04cecb8903939a42b2b9b105
BLAKE2b-256 checksum
How to use checksums
32d15f3ee718b3fc6b90b3a43dcf7e48d9d862f35e57332189a56bf49814402d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.11.3

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page