SVG rendering

The chess.svg module renders SVG Tiny images (mostly for IPython/Jupyter Notebook integration). The piece images by Colin M.L. Burnett are triple licensed under the GFDL, BSD and GPL.

chess.svg.piece(piece: chess.Piece, size: Optional[int] = None) → str[source]

Renders the given chess.Piece as an SVG image.

>>> import chess
>>> import chess.svg
>>>
>>> chess.svg.piece(chess.Piece.from_symbol("R"))  # doctest: +SKIP
_images/wR.svg
chess.svg.board(board: Optional[chess.BaseBoard] = None, *, squares: Union[SupportsInt, Iterable[int], None] = None, flipped: bool = False, coordinates: bool = True, lastmove: Optional[chess.Move] = None, check: Optional[int] = None, arrows: Iterable[Union[chess.svg.Arrow, Tuple[int, int]]] = (), size: Optional[int] = None, style: Optional[str] = None) → str[source]

Renders a board with pieces and/or selected squares as an SVG image.

Parameters:
  • board – A chess.BaseBoard for a chessboard with pieces or None (the default) for a chessboard without pieces.
  • squares – A chess.SquareSet with selected squares.
  • flipped – Pass True to flip the board.
  • coordinates – Pass False to disable coordinates in the margin.
  • lastmove – A chess.Move to be highlighted.
  • check – A square to be marked as check.
  • arrows – A list of Arrow objects like [chess.svg.Arrow(chess.E2, chess.E4)] or a list of tuples like [(chess.E2, chess.E4)]. An arrow from a square pointing to the same square is drawn as a circle, like [(chess.E2, chess.E2)].
  • size – The size of the image in pixels (e.g., 400 for a 400 by 400 board) or None (the default) for no size limit.
  • style – A CSS stylesheet to include in the SVG image.
>>> import chess
>>> import chess.svg
>>>
>>> board = chess.Board("8/8/8/8/4N3/8/8/8 w - - 0 1")
>>> squares = board.attacks(chess.E4)
>>> chess.svg.board(board=board, squares=squares)  # doctest: +SKIP
_images/Ne4.svg
class chess.svg.Arrow(tail: int, head: int, *, color: str = '#888')[source]

Details of an arrow to be drawn.

tail

Start square of the arrow.

head

End square of the arrow.

color = "#888"

Arrow color.