Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

libscid Hero Banner

libscid

PyPI version Python Versions Documentation Licence: GPL-2.0 Typing: Typed

High-performance Python bindings for libscid, the standalone C++ chess game representation, PGN manipulation, and database library derived from Scid and ScidUp.

libscid provides modern, type-safe, and ergonomic Python abstractions for chess game representation, standard-compliant PGN parsing and serialization, functional move tree navigation, FIDE tournament rule adjudication, position analysis, and multi-criteria database search.


1. Key Features

  • Immutable Cursor Navigation: Functional, side-effect-free move tree traversal with explicit mutation semantics for variations and comments.
  • Event-Driven Movetext Streaming: Hierarchical generator stream (iter_movetext) yielding structured events (MovetextLineStart, MovetextMove, MovetextLineEnd) for clean formatting and analysis.
  • FIDE Tournament Arbiter: Accurate adjudication of standard draw claims along any move sequence, including the Fifty-Move Rule and Threefold Repetition.
  • High-Performance Database Engine: In-memory and persistent indexing for Scid databases and PGN archives, enabling rapid header searching, criteria filtering, and sorted index views without parsing full movetext.
  • Type-Safe & Pythonic: Fully typed (PEP 561 compliant), modern Python API (>= 3.10) designed around the principle of Least Surprise.

2. Installation

Install the pre-compiled binary wheel from PyPI:

pip install libscid

3. Quick Start

3.1. Parsing PGN and Navigating Moves

import libscid

# Parse a game from PGN string
pgn_data = """[Event "World Championship"]
[Site "Reykjavik ISL"]
[Date "1972.07.23"]
[Round "6"]
[White "Fischer, Robert J."]
[Black "Spassky, Boris V."]
[Result "1-0"]

1. c4 e6 2. Nf3 d5 3. d4 Nf6 4. Nc3 Be7 5. Bg5 O-O 6. e3 h6 7. Bh4 b6 1-0
"""

game = libscid.Game.from_pgn(pgn_data)
print(f"{game.get_tag('White')} vs {game.get_tag('Black')} ({game.get_tag('Result')})")

# Traverse moves sequentially using an immutable cursor
cursor = game.create_cursor()
while not cursor.is_line_end:
    cursor = cursor.next()
    print(f"Move: {cursor.previous_move_san:<6} FEN: {cursor.position.fen}")

3.2. Hierarchical Movetext & Variation Streaming

import libscid

game = libscid.Game.from_pgn("1. e4 e5 (1... c5 2. Nf3) 2. Nf3 Nc6 *")

for event in game.iter_movetext():
    match event:
        case libscid.MovetextLineStart(variation_depth=depth):
            indent = "  " * depth
            print(f"{indent}[Start Variation (depth {depth})]")
        case libscid.MovetextMove(san=san, comment=comment):
            print(f"{indent}Move: {san}" + (f" ({comment})" if comment else ""))
        case libscid.MovetextLineEnd():
            print(f"{indent}[End Variation]")

3.3. FIDE Tournament Rule Adjudication

import libscid

# Position repeated 3 times in standard play
pgn = "1. Nf3 Nf6 2. Ng1 Ng8 3. Nf3 Nf6 4. Ng1 Ng8 *"
cursor = libscid.Game.from_pgn(pgn).create_cursor().to_game_end()

print("Threefold repetition:", cursor.arbiter.can_claim_threefold_repetition)  # True
print("Fifty-move rule:", cursor.arbiter.can_claim_fifty_move_rule)            # False

3.4. Database Indexing and Multi-Criteria Filtering

import libscid

# Open a PGN archive in read-only mode with instant header indexing
db = libscid.Database.open_pgn_read_only("games.pgn")
print(f"Total indexed games: {db.game_count}")

# Query using structured criteria
criteria = libscid.HeaderCriteria(
    white="Kasparov",
    result="1-0",
    eco_min="B80",
    eco_max="B89",
)

results = db.search.headers(criteria)
print(f"Matching games: {results.game_count}")

# Fetch top results sorted by date descending
for index in results.get_game_indices(sort_criteria="D-", start_row=0, row_count=5):
    print(f"{db.get_tag(index, 'Date')}: {db.get_tag(index, 'White')} vs {db.get_tag(index, 'Black')}")

4. Documentation & Resources


5. Licence

libscid is released under the GNU General Public License v2.0 (GPL-2.0-only). See the COPYING file for full licence details.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

libscid-0.10.0.dev12-py3-none-win_amd64.whl (293.3 kB view details)

Uploaded Python 3Windows x86-64

libscid-0.10.0.dev12-py3-none-manylinux_2_39_x86_64.whl (384.3 kB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

libscid-0.10.0.dev12-py3-none-macosx_15_0_arm64.whl (302.4 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

Details for the file libscid-0.10.0.dev12-py3-none-win_amd64.whl.

File metadata

  • Download URL: libscid-0.10.0.dev12-py3-none-win_amd64.whl
  • Upload date:
  • Size: 293.3 kB
  • Tags: Python 3, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for libscid-0.10.0.dev12-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 fcdedc2ab95553d689c25da4c74222824f68b6dabf48693e2fa519388b791db1
MD5 4255ecd1952b84d2ad4a0759240de749
BLAKE2b-256 45bfa05502747f0f7f96d8d0321294c3a03e98dbfbeb06da77add04ba1aa564a

See more details on using hashes here.

File details

Details for the file libscid-0.10.0.dev12-py3-none-manylinux_2_39_x86_64.whl.

File metadata

  • Download URL: libscid-0.10.0.dev12-py3-none-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 384.3 kB
  • Tags: Python 3, manylinux: glibc 2.39+ x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for libscid-0.10.0.dev12-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 645eda0afeb86feb08fe642e93a40dc49bb335069ab2f4b9ed7a527b836a8c8e
MD5 c6f21a153950772e2287db118c5af524
BLAKE2b-256 237091f83c750e282284cc2a66ba865cddb8f528af596278ce16d958c4c1e660

See more details on using hashes here.

File details

Details for the file libscid-0.10.0.dev12-py3-none-macosx_15_0_arm64.whl.

File metadata

  • Download URL: libscid-0.10.0.dev12-py3-none-macosx_15_0_arm64.whl
  • Upload date:
  • Size: 302.4 kB
  • Tags: Python 3, macOS 15.0+ ARM64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.5 {"installer":{"name":"uv","version":"0.12.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for libscid-0.10.0.dev12-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 befa6385a164e0357fd604eea262e0647b0599b4b5f71ef1799e49d2a2026f56
MD5 7f48c0c57a0289eef3eceba2955e88c5
BLAKE2b-256 058724483188337facb348cb17110c434f889bd5f03c2c58c0d4bb703812489a

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.10.0.dev12 This release

3 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page