{"id":2241,"library":"chess","title":"python-chess","description":"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.","status":"active","version":"1.11.2","language":"en","source_language":"en","source_url":"https://github.com/niklasf/python-chess","tags":["chess","board game","pgn","fen","uci","xboard","engine","game development"],"install":[{"cmd":"pip install chess","lang":"bash","label":"Install core library"}],"dependencies":[{"reason":"Required for Gaviota endgame tablebase probing.","package":"chess-gaviota","optional":true},{"reason":"Required for Syzygy endgame tablebase probing.","package":"chess-syzygy","optional":true},{"reason":"An example extension for building chess engines with python-chess.","package":"python-chess-engine-extensions","optional":true}],"imports":[{"note":"The primary `Board` class is available directly under the `chess` module.","symbol":"Board","correct":"import chess\nboard = chess.Board()"},{"note":"The `Move` class is accessed directly from the `chess` module.","symbol":"Move","correct":"import chess\nmove = chess.Move.from_uci('e2e4')"},{"note":"PGN-related classes like `Game` are in the `chess.pgn` submodule.","wrong":"import chess\ngame = chess.Game()","symbol":"Game","correct":"import chess.pgn\ngame = chess.pgn.Game()"},{"note":"Board classes for chess variants are located in the `chess.variant` submodule.","wrong":"import chess\nboard = chess.CrazyhouseBoard()","symbol":"CrazyhouseBoard","correct":"import chess.variant\nboard = chess.variant.CrazyhouseBoard()"}],"quickstart":{"code":"import chess\n\n# Create a new board\nboard = chess.Board()\nprint(\"Initial board:\\n\" + str(board))\n\n# Make a move\nmove = chess.Move.from_uci(\"e2e4\")\nboard.push(move)\nprint(\"\\nBoard after e4:\\n\" + str(board))\n\n# Check if the game is over\nif board.is_checkmate():\n    print(\"\\nCheckmate!\")\nelif board.is_stalemate():\n    print(\"\\nStalemate!\")\nelse:\n    print(\"\\nGame continues.\")","lang":"python","description":"Initializes a standard chess board, makes a move, and checks the game status."},"warnings":[{"fix":"Upgrade Python to 3.8+ or pin `python-chess<1.11.0`. For `chess.engine` and `chess.Board` subclass changes, consult the v1.11.0 changelog for migration details.","message":"Version 1.11.0 dropped support for Python 3.7. Users on older Python versions must upgrade or use an older `python-chess` version. This release also introduced significant changes to `chess.engine` internals and how subclasses of `chess.Board` handle state recording/restoration.","severity":"breaking","affected_versions":">=1.11.0"},{"fix":"Update code to handle `__reversed__()` as a generator and remove any dependencies on `chess.pgn.ReverseMainline`.","message":"In version 1.5.0, `chess.pgn.Mainline.__reversed__()` changed from returning a list to a generator, and `chess.pgn.ReverseMainline` was removed. This can break code that expected a list or relied on the removed class.","severity":"breaking","affected_versions":">=1.5.0"},{"fix":"Migrate to `chess.pgn.read_headers()` and `chess.pgn.skip_game()` for PGN header scanning and skipping games.","message":"Older versions removed `chess.pgn.scan_headers()` and `chess.pgn.scan_offsets()`, replacing them with `chess.pgn.read_headers()` and `chess.pgn.skip_game()` for similar functionality.","severity":"breaking","affected_versions":"Before 1.x (exact version unclear, pre-1.0)"},{"fix":"Be aware of the relaxed parsing behavior of `parse_san()`. If strict SAN validation is required, consider implementing additional validation logic or parsing using a different method if available.","message":"The `chess.Board.parse_san()` method is designed to be permissive and accepts various syntactical deviations beyond strict SAN (Standard Algebraic Notation), including fully specified moves like 'e2e4', castling with zeros, and null moves. This might lead to unexpected parsing if strict SAN adherence is assumed.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Import variant board classes explicitly from `chess.variant`, e.g., `from chess.variant import CrazyhouseBoard`.","message":"For chess variants (e.g., Crazyhouse, King of the Hill), the specific `Board` classes are located in the `chess.variant` submodule and must be imported from there.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-09T00:00:00.000Z","next_check":"2026-07-08T00:00:00.000Z"}