Skip to main content
Pre-release

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

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.dev10-py3-none-win_amd64.whl (293.1 kB view details)

Uploaded Python 3Windows x86-64

libscid-0.10.0.dev10-py3-none-manylinux_2_39_x86_64.whl (384.0 kB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

libscid-0.10.0.dev10-py3-none-macosx_15_0_arm64.whl (302.2 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: libscid-0.10.0.dev10-py3-none-win_amd64.whl
  • Upload date:
  • Size: 293.1 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.dev10-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 29e72b5d677d4f1d3e4faf8a9abf3b2a46b5765f062e94f1d31ac44a70ee33e5
MD5 b043b28ecedfd587e8336d57155217ec
BLAKE2b-256 7cb1e751da65ad1140d69b242c129af1b3f856e2ed110f391c3e217eb106f575

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libscid-0.10.0.dev10-py3-none-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 384.0 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.dev10-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 45b460d90224b3c729d4024bc70597c3f4014990b432f61b6d4962ac2f7b314e
MD5 da45048fd52a621921ee12e2158863e8
BLAKE2b-256 fa34afd7bf1c435fb07f002bc2a6844fee78610b9e882278baa2d5568cfd0d14

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libscid-0.10.0.dev10-py3-none-macosx_15_0_arm64.whl
  • Upload date:
  • Size: 302.2 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.dev10-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 35bad99454c930724e5689cd37ba41d72e179ac87b067ef1d73e1b6c4b736d59
MD5 ac8ff3b2612608c7a6ffb18e6ee62694
BLAKE2b-256 08f3c8e46398f2df8e2d23f02cba6b79e2e7b43779284664953bd18742b72f58

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.10.0.dev10 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