PySGF
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69243149a92c3fda32d3f84edf47f0171e5d77478d4f2397fef380e1d1c09fac
|
|
| MD5 |
e2b3fe9a91808bdbab58fa5407f73a73
|
|
| BLAKE2b-256 |
fd71267ae49b0d4b7ec94e22158d578d76dfcb35cad806c702c3591501f27bd6
|
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
57a47ef242a8bf18c914d7e5355fe040216cc409bc53c441d3e7143bda17001e
|
|
| MD5 |
0e8f865f182780a579f82a664b1875bb
|
|
| BLAKE2b-256 |
dd19e9f0e42cd54349a8f24f0a00c820accfdce1aa2304e88557c6dae9a1e099
|