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

Uploaded Python 3Windows x86-64

libscid-0.10.0.dev11-py3-none-manylinux_2_39_x86_64.whl (384.2 kB view details)

Uploaded Python 3manylinux: glibc 2.39+ x86-64

libscid-0.10.0.dev11-py3-none-macosx_15_0_arm64.whl (302.3 kB view details)

Uploaded Python 3macOS 15.0+ ARM64

File details

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

File metadata

  • Download URL: libscid-0.10.0.dev11-py3-none-win_amd64.whl
  • Upload date:
  • Size: 293.2 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.dev11-py3-none-win_amd64.whl
Algorithm Hash digest
SHA256 48df3e7f8eac8776a7018116ed0e6e2a3414e126ed1842cc268c726da1c7c669
MD5 c073c8f9f492e6be9dcca36c663cae9a
BLAKE2b-256 7234ef7a4c71a40f14b05a0ace10e5226783da23581f8d868c483d51de03f95f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libscid-0.10.0.dev11-py3-none-manylinux_2_39_x86_64.whl
  • Upload date:
  • Size: 384.2 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.dev11-py3-none-manylinux_2_39_x86_64.whl
Algorithm Hash digest
SHA256 78f204c9ca6c528b9b2e45f3338aa913c017ede572200e5cbea42fa8db44178a
MD5 dd90af1f2910a2002b40e51543727154
BLAKE2b-256 e48e35d2cecbf43dfe31937651a9f5b9e63d5bd971b695e1a604acf1c11e292b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: libscid-0.10.0.dev11-py3-none-macosx_15_0_arm64.whl
  • Upload date:
  • Size: 302.3 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.dev11-py3-none-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 436c82bfd76af8245424be208468407b9df620d913ccb9aa45cb465844168d1d
MD5 cc92bcbd21eb44cded6995f7347ffdce
BLAKE2b-256 233b6a773e329bc11a584d60ae8ac9bcb038ee8b20a3447c29b71c5b2fca0fb8

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

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