I am searching for a program/library in Python which will let two users or a user and an AI play chess with each other.

PS: I have found python-chess. Can this be used for the above along with a chess engine?

3 Answers 3


Yes. You can use the package to play against yourself and an engine. While I don't think there is one function that can do everything for you, but I can give you hints:

To setup up a game against an AI:

  • Read UCI documentation (you can find on Google)
  • Read the UCI functions for python-chess here
  • Spawn an engine thread by engine = chess.uci.popen_engine("/usr/games/stockfish")
  • Start a new game by engine.uci()
  • Send a move by engine.position
  • Start analysis by engine.go
  • Get engine results by command.result()

You will need to read the documentation carefully.

To setup a game against yourself (copied from the package documentation)

>>> import chess

>>> board = chess.Board()

>>> board.push_san("e4")
>>> board.push_san("e5")
>>> board.push_san("Qh5")
>>> board.push_san("Nc6")
>>> board.push_san("Bc4")
>>> board.push_san("Nf6")
>>> board.push_san("Qxf7")
  • Apart from python-chess, is there anything else which not requires to build the above by yourself? (Thanks though!) Commented Jul 25, 2016 at 14:48
  • @theshepherd A GUI like Chessbase, Arena?
    – SmallChess
    Commented Jul 25, 2016 at 15:39
  • Yes but with a CLI interface, so I can parse the results in a Python script. Commented Jul 27, 2016 at 15:59
  • see wiki.bitplan.com/index.php/Python-chess Commented Dec 27, 2019 at 17:54

You mentioned an AI. It might not be very strong, but sunfish is an example of a Python-based chess program, should you decide to go down that route.

Do also bear in mind that XBoard protocol is a valid option, using Polyglot by Fabien Letouzey to convert from UCI to XBoard. It is much harder to convert from XBoard to UCI, through something like WB2UCI by Odd Gunnar Malin, as XBoard is much more lax about things like thinking output.

I would recommend creating an account on the Computer Chess Club if you are going to create a GUI.


Cutechess cli ( https://chessprogramming.wikispaces.com/Cutechess-cli ) by Ilari Pihlajisto, is often used to run automated engine-engine matches. There is also work on a python port. ( http://www.talkchess.com/forum/viewtopic.php?t=60504 ) Github: https://github.com/lucasart/zinc

  • ZINC isn't a python port of cutechess-cli.
    – ZirconiumX
    Commented Aug 14, 2016 at 7:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.