Skip to main content

PyPI version

chess_insight

Modern application for gathering chess data and analyzing chess games.

Features:

  1. Download games from lichess.org and chess.com
  2. Analyze games using set of custom methods and stockfish-16 engine.
  3. Parses games to Game object which contains all information about game and players to python object and json.
  4. Provides method for exporting list of analyzed games to csv

interactive mode

test

installation

  1. pip install chess_insight # download application
    
  2. [Optional] Download stockfish-16 from here

  3. python -m chess_insight # run app
    

Now answer questions and have fun with csv or json data

Python module

pip install chess_insight

[Optional] Download stockfish-16 from here

Usage

  • get games
from chess_insight import ChessComApiCommunicator, LichessApiCommunicator

c1 = LichessApiCommunicator("path/to/stockfish")
c2 = ChessComApiCommunicator("path/to/stockfish" # if blank stocfish wont be used
)

games = list(c1.games_generator("your lichess username", 10, "blitz"))
games += list(c2.games_generator("your chess com username", 10, "blitz"))
  • export games to csv
chess_insight.export_games_to_csv(list(games))

CSV

date host opening opening_short opponent_accuracy_opening_inaccuracy opponent_accuracy_opening_mistake opponent_accuracy_opening_blunder opponent_accuracy_middle_game_inaccuracy opponent_accuracy_middle_game_mistake opponent_accuracy_middle_game_blunder opponent_accuracy_end_game_inaccuracy opponent_accuracy_end_game_mistake opponent_accuracy_end_game_blunder opponent_avg_move_time_opening opponent_avg_move_time_middle_game opponent_avg_move_time_end_game opponent_elo phases_opening phases_middle_game phases_end_game player_accuracy_opening_inaccuracy player_accuracy_opening_mistake player_accuracy_opening_blunder player_accuracy_middle_game_inaccuracy player_accuracy_middle_game_mistake player_accuracy_middle_game_blunder player_accuracy_end_game_inaccuracy player_accuracy_end_game_mistake player_accuracy_end_game_blunder player_avg_move_time_opening player_avg_move_time_middle_game player_avg_move_time_end_game player_elo player_color result time_class time_control url username
2022-05-26 16:51:04 lichess.org Pirc Defense: Classical Variation Pirc Defense 2 2 2 10 11 11 0 0 0 0.25 2.88 2.88 1737 8 51 51 1 0 0 2 1 1 0 0 0 1.0 2.2308 2.2308 1779 white ["white", "timeout"] blitz 180+0 https://lichess.org/vf8yqCKh pro100wdupe
2022-05-11 20:26:37 lichess.org Vienna Game Vienna Game 1 1 1 8 9 9 14 14 14 0.0 2.875 2.2692 1792 3 48 104 0 0 0 3 2 2 0 0 0 1.5 5.9167 3.3462 1790 white ["black", "timeout"] blitz 180+0 https://lichess.org/PjE2bZ8r pro100wdupe
2022-05-11 20:22:35 lichess.org Sicilian Defense: Chekhover Variation Sicilian Defense 0 0 0 1 1 1 0 0 0 1.0 6.2 6.2 1772 7 30 30 2 2 2 5 5 5 0 0 0 0.3333 5.9333 5.9333 1778 black ["black", "timeout"] blitz 180+0 https://lichess.org/y1OSLD9A pro100wdupe
2022-05-05 07:52:37 lichess.org Indian Defense: Knights Variation Indian Defense 0 0 0 1 1 1 4 1 1 0.0 1.7917 2.5211 1789 3 48 142 1 1 1 11 11 11 18 22 22 0.0 2.3333 2.2676 1778 black ["draw", "timeout"] blitz 180+0 https://lichess.org/Yn1BxD8r pro100wdupe
  • get games as dict
for game in games:
    print(game.asdict())

json

{
    "date": datetime.datetime(2023, 9, 14, 21, 57, 47),
    "host": "chess.com",
    "opening": "Sicilian Defense: Closed, Traditional",
    "opening_short": "Sicilian Defense",
    "opponent": {
        "avg_move_time": {"opening": 1.2, "middle_game": 5.1906, "end_game": 3.9467},
        "elo": 1603,
        "evaluation": {
            "opening": {"inaccuracy": 1, "mistake": 1, "blunder": 1},
            "middle_game": {"inaccuracy": 13, "mistake": 13, "blunder": 15},
            "end_game": {"inaccuracy": 6, "mistake": 7, "blunder": 7}
        }
    },
    "phases": {"opening": 4, "middle_game": 64, "end_game": 91},
    "player": {
        "avg_move_time": {"opening": 1.65, "middle_game": 3.4875, "end_game": 3.0109},
        "elo": 1619,
        "evaluation": {
            "opening": {"inaccuracy": 0, "mistake": 0, "blunder": 0},
            "middle_game": {"inaccuracy": 1, "mistake": 1, "blunder": 1},
            "end_game": {"inaccuracy": 1, "mistake": 1, "blunder": 1}
        }
    },
    "player_color": "white",
    "result": ["white", "timeout"],
    "time_class": "blitz",
    "time_control": "180+0",
    "url": "https://www.chess.com/game/live/88467619273",
    "username": "barabasz60"
}

Architecture

Game object

Attribute Description
host Server where game was played.
url Url to game.
player_color Player color in game.
time_control time control in format "time+increment" in seconds. e.g. "600+0" or "180+2"
date Date and time of game in UTC.
result Returns tuple (result, reason) eg: (white, resign) -> white won by resignation
opening_short Short opening name in ECO format. e.g. "Sicilian Defense: Alapin Variation" -> "Sicilian Defense"
phases Phases in half moves https://en.wikipedia.org/wiki/Chess_endgame#The_start_of_the_endgame
host Server where game was played.
username Username of player.
time_class Time class of game.
opening Opening name in ECO format.
player Dict containing player data. Determined by username.
opponent Dict containing opponent data.
url Url to game.

Player object

Attribute Description
elo elo of player at the time of game.
avg_move_time list with average move time for each phase.
evaluation dict with number of mistakes for each phase.
  • example game:

Example charts (Code can be found in here)

image

Release files for chess-insight 0.3.4

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-insight 0.3.4
File Size Uploaded
chess_insight-0.3.4.tar.gz 76.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for chess-insight 0.3.4
File Interpreter ABI Platform
chess_insight-0.3.4-py3-none-any.whl Python 3 none any Details

Total release size: 151.7 kB

Release files / chess_insight-0.3.4.tar.gz

Download URL chess_insight-0.3.4.tar.gz
Size 76.8 kB
Tags Source
SHA-256 checksum
How to use checksums
06083b77c15c5975d8e3d53725951b503160f8287280ea3a4e1ccb71d8db69c7
BLAKE2b-256 checksum
How to use checksums
2018e3ff16badc4ed27762fddeca3cbad9065a6dd3f0b98fded5a123b7bb7d31
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release files / chess_insight-0.3.4-py3-none-any.whl

Download URL chess_insight-0.3.4-py3-none-any.whl
Size 75.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e71d7169817b5e59478262637b31ca117a388034a5d51d656a23c6fda593303
BLAKE2b-256 checksum
How to use checksums
5517e086a8deb39005ec60c83cc7c51d296009de217eacece1036ed836027d13
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.9.18

Release history Release notifications | RSS feed

This release

0.3.4 This release

2 release files

0.3.3

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

0.2.5

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.0.2

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