Skip to content

The Commands ​

Each command the help of scotch lists takes a section below, save scotch cite source, which Citing and Writing a Page sets out, and each section mise run docs:render writes from what the command line declares, meaning the command's docstring, its usage, and the type, the bound, the default, and the help of each parameter. The messages a command exits nonzero on come from src/scotch/docs/stops.toml, which mise run repo:audit holds to the messages the code prints. Beneath each section sits an example run, its output written from the index wherever the index alone sets it. The example runs write the data directory as .cache/data, where a real run prints its full path under the project's root. The Guide walks through a first match.

WritesReads

Commanddownloads/1.1 GBindex/459.9 MB
pgnmentor.com/manifest.jsongames.parquetleft.parquetpositions.binmanifest.json
fetchDownloads the files the store draws its games from.
scotchfetchgamesscotch fetch games writes downloads/www.pgnmentor.com/scotch fetch games writes downloads/manifest.json
indexBuilds the index of stored games from the fetched files.
scotchindexgamesscotch index games reads downloads/www.pgnmentor.com/scotch index games reads downloads/manifest.jsonscotch index games writes index/games.parquetscotch index games writes index/left.parquetscotch index games writes index/positions.binscotch index games writes index/manifest.json
matchMatches a submitted game against the stored games.
scotchmatchgamescotch match game reads downloads/manifest.jsonscotch match game reads index/games.parquetscotch match game reads index/left.parquetscotch match game reads index/positions.binscotch match game reads index/manifest.json
scotchmatchgamesscotch match games reads downloads/manifest.jsonscotch match games reads index/games.parquetscotch match games reads index/left.parquetscotch match games reads index/positions.binscotch match games reads index/manifest.json
showPrints a stored game, a position, or what the store holds.
scotchshowgamescotch show game reads downloads/manifest.jsonscotch show game reads index/games.parquetscotch show game reads index/left.parquetscotch show game reads index/positions.binscotch show game reads index/manifest.json
scotchshowpositionscotch show position reads downloads/manifest.jsonscotch show position reads index/games.parquetscotch show position reads index/left.parquetscotch show position reads index/positions.binscotch show position reads index/manifest.json
scotchshowstorescotch show store reads downloads/manifest.jsonscotch show store reads index/games.parquetscotch show store reads index/left.parquetscotch show store reads index/positions.binscotch show store reads index/manifest.json
citePrints the footnote definition citing a source.
scotchcitesource
Commands
8
Writes
6
Reads
27
Touches
6 of 6 files

scotch fetch games ​

Downloads each file sources.toml declares into the downloads folder of the data directory, in a folder named for the host of its address, and records each one in the manifest.json beside them. A file the manifest records is fetched again where the server reports it changed since, where the copy on disk no longer holds the bytes recorded, or where the server sent it with no entity tag to ask about.

Sends the requests concurrently, one thread per file up to 32, and records and prints each file in the order declared.

Prints one line per file, naming it as fetched or as unchanged, and exits nonzero naming the file and the error where the server answers with an error status, where a request fails once every retry has, where the connection breaks while the file downloads, which no retry covers, or where the file cannot be written, leaving no partial file behind.

text
scotch fetch games

It exits nonzero on each message below.

MessageWhenClears It
Could not fetch <address>: <error>The server answers with an error status, a request fails once every retry has, the connection breaks while the file downloads, or the file cannot be writtenRun the command again once the host answers, or raise SCOTCH_RETRIES or SCOTCH_TIMEOUT_S, or, where the error opens on the system's [Errno <n>], free space on the disk or make the downloads folder writable
bash
scotch fetch games
text
Fetched https://www.pgnmentor.com/players/Abdusattorov.zip
Fetched https://www.pgnmentor.com/players/Adams.zip
Fetched https://www.pgnmentor.com/players/Akobian.zip
…
Fetched https://www.pgnmentor.com/openings/Vienna.zip

scotch index games ​

Reads the games of every file scotch fetch games downloaded into the downloads folder of the data directory, handing the files one at a time to a pool of processes, and writes the index of them to its index folder beside a copy of the manifest the files were read under, writing them beside that folder first and replacing it only once every file is written, so a build cut off partway leaves the earlier index readable. Each file's games are kept under the batches folder of the data directory, in a folder named for the code that reads them, so a file whose bytes and floor are unchanged is read back from there rather than parsed again, and a batch no file reads is removed. Files are parsed largest first and merged in the order sources.toml declares them, so a game several files repeat is indexed under the first, and a game rated below the floor sources.toml sets for its file's section, a game the reader records an error for, or one whose Variant tag names a variant other than standard chess is left out.

Prints the count of games read from each file beside the count left below its floor where its section sets one, one line for each problem of a game left out naming its file, its place there, and its players, and the count of games indexed. Exits nonzero where no file has been fetched, or naming each fetched file whose copy on disk no longer holds the bytes the manifest records.

text
scotch index games

It exits nonzero on each message below.

MessageWhenClears It
<count> keys are shared by different gamesTwo different games hash to one 64-bit keyReport the games sharing a key, since the build refuses to drop either
No file has been fetched under <downloads>The manifest records no file sources.toml declaresRun scotch fetch games
These files changed on disk since their fetch, which `scotch fetch games` downloads again:A fetched file no longer holds the bytes the manifest recordsRun scotch fetch games, which downloads each file named below the line again
bash
scotch index games
text
…
Indexed 1,147,017 games into .cache/data/index

scotch match game ​

Finds the stored game sharing the longest unbroken run of positions with one game of a PGN file.

Prints the stored game as <file>:<n> beside its players, event, and date, the plies the two games share, the Forsyth–Edwards Notation of the position where they part with the move each played from it, the stored game's moves from there through its result, and the count of other stored games sharing a run as long, or a line saying no stored game shares a position with it. Stored games tied on the run rank by the mean of their players' ratings, highest first, then by the one rating a game carries, then in the order the index holds them.

Reads the index from the index folder of the data directory, which is .cache/data under the project's root unless the [tool.scotch] table of its pyproject.toml or the SCOTCH_DATA variable moves it, and warns where a fetch since the index was built recorded other bytes for the files than the ones the index was read from.

Exits nonzero naming the problem where the file cannot be read, holds no game, holds several with none chosen, or holds fewer than the one chosen, where reading the game recorded an error, such as a move illegal in the position it was played from or a FEN tag setting up a position no game reaches, where its Variant tag names a variant other than standard chess, where --json names a path opening on a hyphen other than -, or where no index has been built or the one built holds another layout.

text
scotch match game [OPTIONS] PGN
ParameterAcceptsDefaultMeaning
PGNA pathRequiredThe PGN file holding the game, or - for standard input.
--gameAn integer from 1NoneThe game to match, counting from 1, where the file holds several.
--jsonA pathNoneThe file the match is written to as JSON, or - to print the JSON alone.
--linkA flagOffPrints the address of the Viewer opening the match.
--pliesAn integer from 1NoneThe most plies of the stored game's continuation to print.
--topAn integer from 00The count of further stored games to list after the match.

It exits nonzero on each message below.

MessageWhenClears It
Unknown option: <json>--json names a path opening on a hyphen other than - alonePass the full path, such as $PWD/-match.json
Cannot read <pgn>: <reason>The file cannot be opened, with the reason the system givesName a file that exists and that the user running the command can read
Found no game in <pgn>The file holds no gamePass the file holding the game, a text whose movetext follows its tag pairs
Found several games in <pgn>, which --game chooses amongThe file holds several games and --game names noneChoose one through --game, counting from 1
Found no game <n> in <pgn>The file holds fewer games than --game countsChoose a game the file holds, which scotch match games lists
Found problems in the game in <pgn>:Reading the game recorded an error, such as an illegal move, or its Variant tag names a variant other than standard chessCorrect the move or the tag each line below it names
No index has been built under <index>The data directory holds no indexRun scotch index games
The index under <index> holds another layoutThe index was built in a layout other than the one this version readsRun scotch index games, which rebuilds the index in this layout
bash
scotch match game docs/public/games/demo.pgn --top 3
text
players/Kasparov.zip:193  Kasparov, Gary vs. Sosonko, Gennadi, Tilburg, 1981.??.??
Shares 43 positions, plies 0 to 42 of the submitted game and plies 0 to 42 of the stored game
Parts at r1b2k1r/p3q3/1p1N1p1p/2Ppn3/6pP/2QBP1B1/P3KPP1/3R4 w - - 0 22, where the submitted game played 22. c6 and the stored game played 22. Bc2
Continues 22. Bc2 Ba6+ 23. Ke1 Bc4 24. Nxc4 dxc4 25. Rd6 Re8 26. Bxe5 fxe5 27. Qxc4 Qf7 28. Qe4 g3 29. fxg3 1-0
0 other stored games share a run as long
openings/QGDOther34.zip:16393  Renet,O vs. Dizdar,G, ChIP, 2007.07.12, 21 positions
openings/QGDOther34.zip:19474  Moiseenko,A1 vs. Palac,M, 39th Olympiad Men, 2010.09.23, 20 positions
openings/QGDOther34.zip:13675  Sargissian,G vs. Dizdar,G, ADCF Masters, 2003.08.23, 20 positions

scotch match games ​

Matches every game of a PGN file against the index of stored games.

Prints one line per game, naming it as <file>:<n> beside the stored game closest to it as scotch match game ranks them, or saying no stored game shares a position with it. Where reading a game recorded an error, or its Variant tag names a variant other than standard chess, its line holds the problem in place of a match, and the rest of the report still prints.

Warns where the files changed since the index was built, and exits nonzero naming the problem where the file cannot be read or holds no game, where no index has been built, or where the one built holds another layout.

text
scotch match games PGN
ParameterAcceptsDefaultMeaning
PGNAn existing fileRequiredThe PGN file holding the games.

It exits nonzero on each message below.

MessageWhenClears It
Invalid value "<pgn>" for PGN. "<pgn>" does not exist.The file does not exist, which Cyclopts reports before the command runsName a file that exists
Cannot read <pgn>: <reason>The file cannot be opened, with the reason the system givesName a file that exists and that the user running the command can read
Found no game in <pgn>The file holds no gamePass the file holding the game, a text whose movetext follows its tag pairs
No index has been built under <index>The data directory holds no indexRun scotch index games
The index under <index> holds another layoutThe index was built in a layout other than the one this version readsRun scotch index games, which rebuilds the index in this layout
bash
scotch match games docs/public/games/demo.pgn
text
demo.pgn:1  players/Kasparov.zip:193  Kasparov, Gary vs. Sosonko, Gennadi, Tilburg, 1981.??.??, 43 positions

scotch show game ​

Prints the stored game a <file>:<n> reference names as PGN, for any chess program to open, its tags then its mainline.

Warns where the files changed since the index was built, and exits nonzero naming the problem where the index holds no such game, where no index has been built, or where the one built holds another layout.

text
scotch show game REFERENCE
ParameterAcceptsDefaultMeaning
REFERENCEA wordRequiredThe stored game, as scotch match game names it.

It exits nonzero on each message below.

MessageWhenClears It
No stored game is named <reference>The index holds no game under the referencePass the reference scotch match game printed, such as players/Kasparov.zip:193
No index has been built under <index>The data directory holds no indexRun scotch index games
The index under <index> holds another layoutThe index was built in a layout other than the one this version readsRun scotch index games, which rebuilds the index in this layout
bash
scotch show game players/Kasparov.zip:193
text
[Event "Tilburg"]
[Site "Tilburg"]
[Date "1981.??.??"]
[Round "?"]
[White "Kasparov, Gary"]
[Black "Sosonko, Gennadi"]
[Result "1-0"]
[WhiteElo "2630"]
[BlackElo "2585"]
[ECO "D38"]

1. d4 Nf6 2. c4 e6 3. Nf3 d5 4. Nc3 Bb4 5. cxd5 exd5 6. Bg5 h6 7. Bh4 c5 8. e3 g5 9. Bg3 Ne4 10. Bb5+ Kf8 11. dxc5 Nxc3 12. bxc3 Bxc3+ 13. Ke2 Bxa1 14. Qxa1 f6 15. h4 g4 16. Nd4 Kf7 17. Bd3 Nd7 18. Qc3 Ne5 19. Nb5 Qe7 20. Nd6+ Kf8 21. Rd1 b6 22. Bc2 Ba6+ 23. Ke1 Bc4 24. Nxc4 dxc4 25. Rd6 Re8 26. Bxe5 fxe5 27. Qxc4 Qf7 28. Qe4 g3 29. fxg3 1-0

scotch show position ​

Reports what the stored games played from one position.

Prints how many stored games reach it, each move they played from it with how many games played it and how those games ended, the games ending at the position under end, and then the games themselves, newest first, each named as <file>:<n>. A game reaching the position twice counts once, under the move it played from its first reach. A line of moves is read as PGN, so it may hold move numbers, comments, annotation marks, and a result beside its moves.

Warns where the files changed since the index was built, and exits nonzero naming the problem where a token opening on a hyphen names no option, where a Forsyth–Edwards Notation names no position or stops short of its first four fields, since a placement alone would read as white to move with no castling rights, where a line of moves holds an illegal move, a word naming no move, a ( or a { never closed, a ( before any move, a ) with none open, or more past the blank line or the result ending its moves, where no index has been built, or where the one built holds another layout.

text
scotch show position [OPTIONS] [ARGS...]
ParameterAcceptsDefaultMeaning
POSITIONAny number of wordsNoneThe Forsyth–Edwards Notation of the position or a line of moves from the start, quoted or not, the starting position where left out.
--topAn integer from 120The count of games to list, the newest first.

It exits nonzero on each message below.

MessageWhenClears It
Unknown option: <token>A word of the position opens on a hyphen and names no optionName the flag the help lists, or remove the word
The FEN <position> stops short of its first four fields, the placement, the side to move, the castling rights, and the en passant square, which together name a positionA FEN holds fewer than four fieldsWrite the placement, the side to move, the castling rights, and the en passant square
names no position: <fen>A FEN names no position a game can reachCorrect the FEN, whose placement names eight ranks and one king of each color
Found problems in <position>:A line of moves holds an illegal move, a word naming no move, a bracket left open or closed with none open, or more past a blank line or on a line past its resultCorrect the move or the word each line below it names
names no move: '<word>'A word of a line of moves reads as no move, beneath the line naming the problemsSpell the move in SAN, or remove the word
holds more past the end of its movesA line of moves holds text past a blank line or on a line past its result, beneath the line naming the problemsRemove the blank line or the result, or what follows it
No index has been built under <index>The data directory holds no indexRun scotch index games
The index under <index> holds another layoutThe index was built in a layout other than the one this version readsRun scotch index games, which rebuilds the index in this layout
bash
scotch show position 1. d4 Nf6 2. c4 e6 --top 3
text
124,053 stored games reach this position
Nc3        56,847  1-0 19,994  1/2-1/2 20,878  0-1 15,971  * 4
Nf3        55,988  1-0 18,740  1/2-1/2 23,799  0-1 13,443  * 6
g3         10,890  1-0 3,476  1/2-1/2 4,367  0-1 3,045  * 2
Bg5           182  1-0 111  1/2-1/2 46  0-1 25  * 0
Bf4            58  1-0 24  1/2-1/2 16  0-1 18  * 0
a3             45  1-0 19  1/2-1/2 11  0-1 15  * 0
e3             23  1-0 5  1/2-1/2 8  0-1 10  * 0
g4             11  1-0 6  1/2-1/2 4  0-1 1  * 0
Qc2             4  1-0 1  1/2-1/2 3  0-1 0  * 0
Bd2             1  1-0 0  1/2-1/2 1  0-1 0  * 0
b3              1  1-0 0  1/2-1/2 1  0-1 0  * 0
d5              1  1-0 0  1/2-1/2 1  0-1 0  * 0
f3              1  1-0 0  1/2-1/2 1  0-1 0  * 0
end             1  1-0 1  1/2-1/2 0  0-1 0  * 0
Newest first:
players/Karjakin.zip:3599  Tomashevsky,E vs. Karjakin,Sergey, Chess Stars 6.0 Blitz, 2026.07.06
players/Tomashevsky.zip:2073  Tomashevsky,E vs. Sadhwani,Raunak, Chess Stars 6.0 Blitz, 2026.07.06
players/Tomashevsky.zip:2079  Gunina,V vs. Tomashevsky,E, Chess Stars 6.0 Blitz, 2026.07.06

scotch show store ​

Reports what the store holds.

Prints each file sources.toml declares with its size and fetch date, the games and positions the index holds, whether the files have changed since the index was built from them, and the command to run next.

text
scotch show store
bash
scotch show store
text
…
The index holds 1,147,017 games and 98,072,952 positions
The index was built from the files as fetched
Next: scotch match game <pgn>
Built from22ebd11
CodeJybbs/scotch
GamesPGN Mentor
Crateshakmaty, GPL
FacesSIL OFL 1.1
PiecesCburnett, BSD

Scotch 0.2.0, under the GPL-3.0-or-later.