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.

Download files

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

Source Distribution

pysgf-1.0.0.tar.gz (62.6 kB view details)

Uploaded Source

Built Distribution

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

pysgf-1.0.0-py3-none-any.whl (9.2 kB view details)

Uploaded Python 3

File details

Details for the file pysgf-1.0.0.tar.gz.

File metadata

  • Download URL: pysgf-1.0.0.tar.gz
  • Upload date:
  • Size: 62.6 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for pysgf-1.0.0.tar.gz
Algorithm Hash digest
SHA256 69243149a92c3fda32d3f84edf47f0171e5d77478d4f2397fef380e1d1c09fac
MD5 e2b3fe9a91808bdbab58fa5407f73a73
BLAKE2b-256 fd71267ae49b0d4b7ec94e22158d578d76dfcb35cad806c702c3591501f27bd6

See more details on using hashes here.

File details

Details for the file pysgf-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pysgf-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 9.2 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for pysgf-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 57a47ef242a8bf18c914d7e5355fe040216cc409bc53c441d3e7143bda17001e
MD5 0e8f865f182780a579f82a664b1875bb
BLAKE2b-256 dd19e9f0e42cd54349a8f24f0a00c820accfdce1aa2304e88557c6dae9a1e099

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page