Skip to main content

PySGF

CI PyPI version Ruff

PySGF is a lightweight but powerful parser for Go game records, supporting the SGF format as well as NGF and GIB.

Quickstart

from pysgf import GoGame

# parse either a string ..
root = GoGame.parse(input_sgf)
# or pass a file name. It will try to detect the encoding specified in the record file.
# files ending in .ngf or .gib are parsed as those formats instead.
root = GoGame.parse_file(input_file_name)
# all properties are stored as lists, but you can ask for the first
root.get_list_property("AB")
root.get_property("KM")
move = root.move  # returns a Move object with options for SGF, GTP or 0- based coordinates
children = root.children  # returns all child nodes

parse/parse_sgf/parse_file return the root node. To keep the game object itself, use GoGame.from_string(contents, ext="sgf") or GoGame.from_file(filename) and access game.root.

Extending

GoGame and GoNode are the concrete classes for everyday use. Projects that need to attach their own state or behaviour to nodes can subclass the generic base classes, which keeps parent, children and play() typed as the subclass:

from pysgf import BaseGoGame, BaseGoNode


class MyNode(BaseGoNode["MyNode"]):
    def __init__(self, parent=None, properties=None, move=None):
        super().__init__(parent=parent, properties=properties, move=move)
        self.my_analysis = None


class MyGame(BaseGoGame[MyNode]):
    NODE_TYPE = MyNode


root = MyGame.parse(input_sgf)  # -> MyNode

Requirements

Python 3.11 or newer.

Documentation

Building the documentation needs the docs dependency group. Install it first — building against a system-wide Sphinx (e.g. Debian/Ubuntu's python3-sphinx) will fail with no theme named 'sphinx_rtd_theme' found, since the packaged theme is usually missing or too old:

uv sync --group docs
uv run make -C docs html

Without uv:

pip install -e . "sphinx>=9,<10" "sphinx-rtd-theme>=3.1,<4"
make -C docs html

Note the -e . — autodoc imports pysgf to document it, so the package has to be installed in the same environment as Sphinx. The generated HTML lands in docs/build/html.

Metadata

Release files for pysgf 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pysgf 1.0.0
File Size Uploaded
pysgf-1.0.0.tar.gz 62.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pysgf 1.0.0
File Interpreter ABI Platform
pysgf-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 71.8 kB

Release files / pysgf-1.0.0.tar.gz

Download URL pysgf-1.0.0.tar.gz
Size 62.6 kB
Tags Source
SHA-256 checksum
How to use checksums
69243149a92c3fda32d3f84edf47f0171e5d77478d4f2397fef380e1d1c09fac
BLAKE2b-256 checksum
How to use checksums
fd71267ae49b0d4b7ec94e22158d578d76dfcb35cad806c702c3591501f27bd6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
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}

Release files / pysgf-1.0.0-py3-none-any.whl

Download URL pysgf-1.0.0-py3-none-any.whl
Size 9.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
57a47ef242a8bf18c914d7e5355fe040216cc409bc53c441d3e7143bda17001e
BLAKE2b-256 checksum
How to use checksums
dd19e9f0e42cd54349a8f24f0a00c820accfdce1aa2304e88557c6dae9a1e099
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
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}

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

0.9.0

2 release files

0.8.0

2 release files

0.7.0

2 release 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