Read ChessBase databases and opening books directly from Rust.
Native, read-only support for classic .cbh, modern .2cbh and opening books .ctg, plus PGN export, search, parallel conversion and .cbv/.cbz archive extraction.
Read native ChessBase databases and opening books without converting them. cbvault is designed for chess software, opening explorers, research tools, batch-processing pipelines and anyone who needs to work with large ChessBase collections without ChessBase itself. It is an independent MIT-licensed project, not affiliated with ChessBase.
| What you need | What cbvault provides |
|---|---|
| Read existing databases | Open classic .cbh and modern .2cbh file sets in place. Keep stable source game IDs; no imported copy or proprietary runtime required. |
| Explore opening books | Open .ctg books directly, probe positions and legal moves, inspect game/result/rating statistics and annotations, and verify complete books. |
| Build chess applications | One generation-aware Database API for headers, players and events, moves, variations, annotated games and PGN. |
| Search millions of games | Indexed-style metadata filters and name lookups, plus on-demand position replay and Polyglot position keys, with cancellation and early stopping. |
| Process without loading everything | Borrowed game records, optional keys and annotations, memory-mapped reads where supported, and deterministic parallel conversion/export. |
| Recover ChessBase archives | Extract .cbv and password-protected .cbz using all four archive compression modes. |
| Own your integration | Pure Rust, MIT, read-only source access, typed errors, and gigachess as the sole chess-rules engine. |
Unlike a workflow that requires importing an entire collection into a new database format, cbvault can read the original files directly. It is a library and CLI rather than a full chess GUI. The downstream application chooses how to store, index or display the results.
Requires Rust 1.88+.
cargo add cbvault@0.3.0
cargo install cbvault-cli --version 0.3.0Open a database with Rust. Pass either a classic .cbh file, a modern .2cbh file, or an unambiguous database base path:
use cbvault::bridge::{Database, GameBuf};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let db = Database::open("MyDatabase.2cbh")?;
println!("{}: {} records", db.generation(), db.records());
let mut buffer = GameBuf::new();
// Include annotations in the PGN for game record 1.
let pgn = db.game_pgn_with(1, &mut buffer, true)?;
println!("{pgn}");
Ok(())
}Or export games without writing Rust:
cbvault info "MyDatabase.2cbh" --games 5
cbvault verify "MyDatabase.2cbh" --threads 8
cbvault pgn "MyDatabase.2cbh" games.pgn --threads 8
cbvault archive list "Collection.cbv"
cbvault archive extract "Collection.cbv" ./extracted --threads 8
cbvault search "MyDatabase.2cbh" --white "Carlsen, Magnus" --ignore-colours --elo 2700- --elo-mode both --pgn found.pgnThe same database commands also work with classic .cbh files; archive commands accept .cbz with --password. The CLI can emit machine-readable JSON and redirect PGN to stdout.
CTG opening books are supported from v0.2.0. Probe a position, inspect its moves and result/rating statistics, or verify the book's keys, move decoding and child positions:
cbvault book info "MyBook.ctg"
cbvault book probe "MyBook.ctg" --moves e4 c5 Nf3 --json
cbvault book verify "MyBook.ctg" --children --jsonDirect database browsing. List games, inspect player/event metadata, open a game with its annotations and variations, or export a selected record to PGN. Headers can be read independently of move decoding.
Search and preparation. Filter by players, ECO, result, year, rating or round. cbvault::query and cbvault search support composable ChessBase-style Game data criteria: names with "ignore colours" and "wins only", tournament, annotator, date and ECO ranges, move count, Elo in each mode with a rating difference, results including mate, stalemate and check, guiding texts, "any text" and native 2CBH time control (docs/search.md). Resolve multiple matching player IDs instead of silently picking one. Scan positions with legal replay, stop when enough results are found, or generate Polyglot keys for a separate opening index.
High-throughput data pipelines. Use GameSink with for_each_game, for_each_range or convert_parallel. Each callback receives borrowed game data; the sink can request moves, keys and/or native annotations as needed. Parallel processing preserves source record order, so consumers do not need to reorder games afterward.
Portable PGN export. Export entire sets or game ranges from both .cbh and .2cbh, including supported annotations and variations. Sequential and parallel paths are regression-tested for deterministic output.
Opening books. The read-only CTG reader was originally contributed by Tulio Vianna in PR #8, with subsequent maintainer review and compatibility fixes. Open a ChessBase .ctg book and probe positions for legal moves, game/result and rating statistics, move annotations and evaluations. Verify every position key and move, optionally checking that each move leads to another indexed position. The normal Book reader uses native CTO/CTB routing with validation and automatic scan fallback; valid native books need no synthesized index. CTG-only sets fall back to a scan (about eight bytes per position).
Archive migration and recovery. List or extract .cbv/.cbz members without implementing a ChessBase archive reader yourself. On the tested reference archive, cbvault reproduced all 3,871 members (3.61 GB extracted) byte-for-byte against the reference extraction.
See Rust API documentation, CLI crate, and the consumer API guide.
Game Data search was originally contributed by Tulio Vianna in PR #9. The integrated version adds reusable query/page plans, Unicode normalization, positioned I/O support, specialized header predicates and faster ending replay.
Median speedups from cross-platform CI run 46332645439 on generated databases (candidate f7822cd):
| Workload | Linux | macOS | Windows |
|---|---|---|---|
| No-match search | 13.68× | 12.62× | 12.26× |
| Name search | 3.15× | 2.74× | 2.55× |
| Combined search | 5.91× | 3.51× | 8.09× |
| Checkmate search | 5.10× | 6.80× | 5.88× |
| Bridge IDs | 2.17× | 2.23× | 2.13× |
| Bridge pagination | 2.20× | 2.01× | 1.95× |
Ratios are medians of per-configuration speedups (reciprocal median latency ratio across equivalent configurations); new queries compare with original PR #9, existing bridge operations with pre-integration v0.3. Linux uses 20k/100k/1M records and seven samples, macOS/Windows use 20k and 41 samples; both I/O modes and 1/4 workers. These are not general speed guarantees or claims of superiority to ChessBase itself. See v0.3 release validation for private results, remaining timing variability and unverified ChessBase semantics.
| Area | Evidence | Boundary |
|---|---|---|
Native .2cbh read and PGN |
3,410,497 games in a frozen Mega Database 2026 / ChessBase 18 exported PGN sample; zero reported unexplained canonical-byte differences after counted, audited presentation exceptions | This is not raw PGN byte identity, universal compatibility, or a comparison of the later 8,330,763 eligible games (their headers were classified only). |
| Archive extraction | 3,871 / 3,871 members, 3.61 GB extracted, byte-identical to reference on the tested archive | Verified on the stated reference corpus, not every possible archive |
Classic .cbh throughput |
1.17–1.20× faster than the MIT cbformat reference during like-for-like verify benchmarks on a 10-core Apple Silicon machine |
A measured classic-CBH workload, not a universal speed comparison or a benchmark for 2CBH |
| CTG opening books | Exhaustive checks across nine commercial, Mega-derived, CC0-scale, and controlled .ctg/.cto/.ctb books: 228,697,037 positions and 232,736,748 decoded moves with zero bad keys, key mismatches, duplicate keys, illegal/unknown moves, missing children, or missed .cto/.ctb routes. Controlled full-tree parity matched 212 / 212 (100%) normalized nodes on special-ctg-standard-v3 and special-ctg-coverage-v3; 338,673 / 339,155 (99.86%) sampled Mega positions matched eight statistics after CTG symmetry. |
Controlled special-*-v3.ctg books truncate at ply 33 and exclude SetUp games; fourth-piece (ordinal >= 3) codes are unobserved, and underpromotions cannot be encoded in parent CTG move bytes. See independent CTG validation. |
| Platform and correctness | GitHub CI on Windows, macOS and Linux, generated malformed-input tests, fuzz targets, Clippy and example tests | Real proprietary ChessBase oracle data stays local; CI cannot rerun it |
Known limits (opening books): Book reads .cto/.ctb natively with automatic fallback to ScanBook. NativeBook is the explicit directory-only reader. Move symbols, colours, the "Main move"/"Don't play" marks, and common position evaluations are decoded; unknown annotation bits and raw_tail[1]/raw_score anomalies are exposed raw. Book move encoding omits underpromotions (0 decoded, 587 underpromotion-only child omissions), and V4 establishes 228 fixed move codes plus a non-fixed overflow marker (0x1f); overflow children are discoverable but not stored continuations. Complete numerical parity on commercial/Mega exports remains bounded where original ChessBase import settings are unavailable.
Known limits: cbvault is read-only and does not edit/write ChessBase databases, parse PGN as an input format, or provide a GUI. Other real 2CBH corpora, rare native annotations and multimedia, ChessBase-specific GUI/training metadata and real-world Chess960 need further verification. The project remains pre-1.0. For exact comparisons and exclusions, see the archived 2CBH acceptance report.
| Crate | Responsibility |
|---|---|
cbvault |
Public read-only API: classic/2CBH databases, CTG book probing/verification, search, game sinks, PGN and conversion |
cbvault-format |
Binary records for .cbh/.2cbh, .ctg books and .cbv/.cbz archives |
cbvault-chess |
Legal move replay and 16-bit moves2 conversion using gigachess |
cbvault-cli |
CLI for database inspection, CTG book probing/verification, PGN export and archive extraction |
No second chess engine is bundled. The library reads source databases without modifying them, leaving index/storage design to consumers.
CBVault uses GigaChess Rust for legal move replay and moves2 conversion rather than maintaining a second chess engine. To build a chess database or opening explorer with a browser interface, use GigaChess JS/TS for local position handling and GigaBoard for the React UI. Encode positions at the application boundary using GigaChess; CBVault is not itself a network transport.
| Project | Use it for |
|---|---|
| GigaChess JS/TS | Pure JavaScript/TypeScript chess rules, move generation and game replay in browsers or Node.js |
| GigaChess Rust | Native chess rules, legal move generation and high-throughput game replay |
| GigaBoard | Accessible, high-performance React chessboard UI |
| CBVault (this library) | Read ChessBase databases and opening books, search games and export PGN |
Board96 v1 is a canonical 96-byte little-endian position format shared by GigaChess JS/TS and Rust, alongside the 16-bit moves2 encoding. A web or desktop frontend and a Rust backend can exchange compatible positions using the checked binary codecs instead of repeatedly formatting and parsing FEN. This is a wire-format contract, not a guarantee about JavaScript object size, native memory layout, network latency or compatibility with older releases.
All four projects are MIT-licensed and separately distributed. You do not need to adopt the entire stack; each package brings only its own dependencies.
cbvault is MIT-licensed and based on the MIT-era cbformat implementation from oschess-cb-bridge. The pinned upstream foundations are:
- Classic CBH: MIT v1.0.0, commit
ca9e8f8e. - Native 2CBH: MIT v1.0.3, commit
bffebfc4.
We did not copy, vendor, link or port the upstream code introduced after its switch to AGPL-3.0. Later format observations were reconciled as independently verified facts, not source-code reuse. The MIT notice and modifications are tracked in the provenance ledger and third-party notices. The archive codecs were independently implemented from format facts. No ChessBase proprietary code or databases are distributed.
License: MIT. ChessBase is a trademark of its owner; cbvault is independent and not affiliated with or endorsed by ChessBase.
Contributions are welcome, especially reproducible format-compatibility reports, small redistributable test fixtures, correctness tests, performance comparisons and documentation. Start with CONTRIBUTING.md or open an issue. Please avoid sharing copyrighted or private database contents; describe the affected format and version and provide a minimal legal fixture where possible.
API guide · CTG validation · Format specifications · 2CBH research and limitations · Performance/codec reference · Changelog · Contributing
Development plans: roadmap, public benchmark corpus, and deferred write support.
