python-chess

1.11.2 · active · verified Thu Apr 09

python-chess is a comprehensive Python library designed for chess programming. It provides core functionalities like move generation, move validation, and support for common chess formats such as PGN, FEN, and EPD. Additionally, it offers features for Polyglot opening book probing, Gaviota and Syzygy endgame tablebase probing, and communication with UCI/XBoard chess engines. The library is actively maintained, with the current stable version being 1.11.2, released in February 2025.

Warnings

Install

Imports

Quickstart

Initializes a standard chess board, makes a move, and checks the game status.

import chess

# Create a new board
board = chess.Board()
print("Initial board:\n" + str(board))

# Make a move
move = chess.Move.from_uci("e2e4")
board.push(move)
print("\nBoard after e4:\n" + str(board))

# Check if the game is over
if board.is_checkmate():
    print("\nCheckmate!")
elif board.is_stalemate():
    print("\nStalemate!")
else:
    print("\nGame continues.")

view raw JSON →