Formats¶
The module lichess.format
lets you choose the format for games and other data (JSON
, PGN
, SINGLE_PGN
, or PYCHESS
).
-
lichess.format.
PGN
= <lichess.format._Pgn object>¶ Produces a PGN string, or a generator for PGN strings of each game.
>>> from lichess.format import PGN >>> >>> pgn = lichess.api.game('Qa7FJNk2', format=PGN) >>> print(pgn) [Event "Casual rapid game"] ... >>> pgns = lichess.api.user_games('cyanfish', max=50, format=PGN) >>> print(len(list(pgns))) 50
-
lichess.format.
SINGLE_PGN
= <lichess.format._SinglePgn object>¶ Produces a PGN string, possibly containing multiple games.
>>> from lichess.format import0 SINGLE_PGN >>> >>> pgn = lichess.api.user_games('cyanfish', max=50, format=SINGLE_PGN) >>> print(pgn) [Event "Casual rapid game"] ...
-
lichess.format.
PYCHESS
= <lichess.format._PyChess object>¶ Produces a python-chess game object, or a generator for multiple game objects.
>>> from lichess.format import PYCHESS >>> >>> game = lichess.api.game('Qa7FJNk2', format=PYCHESS) >>> print(game.end().board()) . . k . R b r . . p p r . N p . p . . . . . . p . . . . . . . . . . . p . . . . P . . P . . . P . P P . . P P . . . K R . . . .
-
lichess.format.
JSON
= <lichess.format._Json object>¶ Produces a dict representing a JSON object, or a generator for multiple dicts. This is the default format.
>>> from lichess.format import JSON >>> >>> game = lichess.api.game('Qa7FJNk2', format=JSON) # or leave out >>> print(game['players']['white']['user']['id']) cyanfish