pychess.Savers package¶
Submodules¶
pychess.Savers.ChessFile module¶
-
class
pychess.Savers.ChessFile.ChessFile(file)¶ Bases:
objectThis class describes an opened chessfile. It is lazy in the sense of not parsing any games, that the user don’t request. It has no catching.
-
close()¶
-
get_book_moves(fen=None)¶
-
get_date(gameno)¶ Returns a tuple (year,month,day) of the game date Default is current time if nothing is specified in the file
-
get_elo(gameno)¶ Returns a tuple of the players rating in ELO format Default is 1600 if nothing is specified in the file
-
get_event(gameno)¶ Returns the event at which the game took place Could be “World Chess Cup” or “My local tournament” Default is “?” if nothing is specified in the file
-
get_id(gameno)¶
-
get_info(gameno)¶
-
get_player_names(gameno)¶ Returns a tuple of the players names Default is (“Unknown”, “Unknown”) if nothing is specified
-
get_records(direction=0)¶
-
get_result(gameno)¶ Returns the result of the game Can be any of: RUNNING, DRAW, WHITEWON or BLACKWON Default is RUNNING if nothing is specified in the file
-
get_round(gameno)¶ Returns the round of the event at which the game took place Pgn supports having subrounds like 2.1.5, but as of writing, only the first int is returned. Default is 1 if nothing is specified in the file
-
get_site(gameno)¶ Returns the location at which the game took place Default is “?” if nothing is specified in the file
-
get_variant(gameno)¶
-
loadToModel(gameno, position, model=None)¶ Load the data of game “gameno” into the gamemodel If no model is specified, a new one will be created, loaded and returned
-
set_fen_filter(fen)¶
-
set_scout_filter(query)¶
-
pychess.Savers.chessalpha2 module¶
pychess.Savers.database module¶
-
class
pychess.Savers.database.TagDatabase(engine)¶ Bases:
object-
build_order_by(order_col, is_desc)¶
-
build_query()¶
-
build_where_offs(offset_list)¶
-
build_where_offs8(offset_list)¶
-
close()¶
-
get_count()¶
-
get_info(rec)¶
-
get_records(last_seen, limit)¶
-
property
count¶
-
-
pychess.Savers.database.parseDateTag(tag)¶
-
pychess.Savers.database.save(path, model, offset, flip=False)¶
pychess.Savers.epd module¶
-
class
pychess.Savers.epd.EpdFile(handle)¶ Bases:
pychess.Savers.ChessFile.ChessFile-
create_rec(line)¶
-
get_player_names(rec)¶ Returns a tuple of the players names Default is (“Unknown”, “Unknown”) if nothing is specified
-
loadToModel(rec, position, model=None)¶ Load the data of game “gameno” into the gamemodel If no model is specified, a new one will be created, loaded and returned
-
-
pychess.Savers.epd.load(handle)¶
-
pychess.Savers.epd.save(handle, model, position=None, flip=False)¶ Saves game to file in fen format
pychess.Savers.fen module¶
-
class
pychess.Savers.fen.FenFile(handle)¶ Bases:
pychess.Savers.ChessFile.ChessFile-
loadToModel(rec, position, model=None)¶ Load the data of game “gameno” into the gamemodel If no model is specified, a new one will be created, loaded and returned
-
-
pychess.Savers.fen.load(handle)¶
-
pychess.Savers.fen.save(handle, model, position=None, flip=False)¶ Saves game to file in fen format
pychess.Savers.pgn module¶
-
class
pychess.Savers.pgn.PGNFile(handle, progressbar=None)¶ Bases:
pychess.Savers.ChessFile.ChessFile-
close()¶
-
get_book_moves(fen)¶ Get move-games-win-loss-draw stat of fen position
-
get_count()¶ Number of games in .pgn database
-
get_movetext(rec)¶
-
get_offs(skip, filtered_offs_list=None)¶ Get offsets from .scout database and create where clause we will use to query header tag .sqlite database
-
get_offs8(skip, filtered_offs_list=None)¶ Get offsets from .bin database and create where clause we will use to query header tag .sqlite database
-
get_records(direction=0)¶ Get game header tag records from .sqlite database in paginated way
-
get_size()¶ Size of .pgn file in bytes
-
get_variant(rec)¶
-
has_position(fen)¶
-
init_chess_db()¶ Create/open polyglot .bin file with extra win/loss/draw stats using chess_db parser from https://github.com/mcostalba/chess_db
-
init_scoutfish()¶ Create/open .scout database index file to help querying using scoutfish from https://github.com/mcostalba/scoutfish
-
init_tag_database(importer=None)¶ Create/open .sqlite database of game header tags
-
loadToModel(rec, position=- 1, model=None)¶ Parse game text and load game record header tags to a GameModel object
Reads header tags from pgn if pgn is a one game only StringIO object
-
parse_movetext(string, board, position, variation=False)¶ Recursive parses a movelist part of one game.
Arguments: srting - str (movelist) board - lboard (initial position) position - int (maximum ply to parse) variation- boolean (True if the string is a variation)
-
reset_last_seen()¶
-
set_fen_filter(fen)¶ Set fen string we will use to get game offsets from .bin database
-
set_scout_filter(query)¶ Set json string we will use to get game offsets from .scout database
-
set_tag_filter(query)¶ Set (now prefixing) text and create where clause we will use to query header tag .sqlite database
-
set_tag_order(order_col, is_desc)¶
-
property
count¶ Number of games in .pgn database
-
property
size¶ Size of .pgn file in bytes
-
-
pychess.Savers.pgn.load(handle, progressbar=None)¶
-
pychess.Savers.pgn.move_count(node, black_periods=False)¶
-
pychess.Savers.pgn.msToClockTimeTag(ms)¶ Converts milliseconds to a chess clock time string in ‘WhiteClock’/ ‘BlackClock’ PGN header format
-
pychess.Savers.pgn.nag2symbol(nag)¶
-
pychess.Savers.pgn.parseClockTimeTag(tag)¶ Parses ‘WhiteClock’/’BlackClock’ PGN headers and returns the time the player playing that color has left on their clock in milliseconds
-
pychess.Savers.pgn.parseTimeControlTag(tag)¶ Parses ‘TimeControl’ PGN header and returns the time and gain the players have on game start in seconds
-
pychess.Savers.pgn.save(handle, model, position=None, flip=False)¶ Saves the game from GameModel to .pgn
-
pychess.Savers.pgn.symbol2nag(symbol)¶
-
pychess.Savers.pgn.walk(node, result, model, save_emt=False, save_eval=False, vari=False)¶ Prepares a game data for .pgn storage. Recursively walks the node tree to collect moves and comments into a resulting movetext string.
Arguments: node - list (a tree of lboards created by the pgn parser) result - str (movetext strings)
pychess.Savers.png module¶
-
pychess.Savers.png.save(file, model, position=None, flip=False)¶ Export the current position into a .png file