Skip to main content
Pre-release

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

GNU Backgammon (GNUBG)

PyPI Downloads Conda Downloads GitHub issues License Stack Overflow

GNU Backgammon Python bindings bring the powerful GNUBG engine to Python 3.

Quick Start

gnubg is a native Python extension module that wraps the GNU Backgammon engine, so you can call the same position-analysis and cube-decision routines that power the GUI from any Python 3.8–3.13 script or application. It’s ideal for batch processing, data-science workflows, or building custom tools and UIs.

Installation

pip install gnubg

Getting Started

import gnubg

# Load the engine (weights, bear-off tables, etc. are initialized)
gnubg.initnet()

# Convert a position key (20-char A–Z or 14-char Base64) to a board
board = gnubg.boardfromkey("4HPwATDgc/ABMA")

# Evaluate win/gammon/backgammon probabilities and equity at 4 plies
win, gamm, bg, equity = gnubg.probabilities(board, 4)

print(f"Win: {win:.3f}, Gammon: {gamm:.3f}, Backgammon: {bg:.3f}, Equity: {equity:.3f}")

That’s all you need to get up and running! For detailed API docs, advanced build options, and configuration, see the sections below or visit the full documentation on ReadTheDocs.

Data files: Weights, bearoff tables, and match-equity data are included in the package and loaded from the directory next to the compiled extension (gnubg/data). No environment variable is required for normal installs. To override the location (e.g. for a custom build), set GNUBG_DATA_DIR to the directory containing gnubg.weights.

API style: All functions in the C extension are also available in snake_case format (e.g., find_best_move instead of findbestmove, position_from_id instead of positionfromid). The original camelCase names remain available for backward compatibility. The snake_case variants are the recommended idiomatic Python API.

Output: gnubg prints its messages (e.g. from gnubg.command(...)) to the process's standard output and error streams. To keep stdout free, for example in a program that speaks a protocol on it, route them with gnubg.set_output(out, err). Each target can be a callable taking a str, or anything with a write() method: gnubg.set_output(sys.stderr, sys.stderr), gnubg.set_output(lambda s: None, lambda s: None) to silence, or gnubg.set_output(lambda s: log.info(s.rstrip())). gnubg.set_output() restores the default.

Examples: Example projects (e.g. a REST API for best-move and evaluation) are distributed with the package under gnubg/examples/. After installing, find them with import gnubg, os; print(os.path.join(os.path.dirname(gnubg.__file__), 'examples')). See the README.md in that directory for how to run them.

It provides:

  • Engine initialization & data loading (neural-net weights, opening-book, bear-off tables)
  • Position classification (classify) & public-evaluation best move (pub_best_move)
  • Board ↔ ID conversions (board_from_position_id, board_from_position_key, key_of_board, position_id)
  • Dice utilities (roll) & cube utilities (best_move, pub_eval_score)
  • Bear-off tools (bearoff_id_2_pos, bearoff_probabilities)
  • Legal-move enumeration (moves) & probabilistic evaluation (probabilities)
  • Monte-Carlo rollouts (rollout, cubeful_rollout)
  • Equity lookup (equities.value(xAway, oAway))
  • Runtime engine tuning via the set submodule

🧪 Platform Compatibility

Python Version Linux x86_64
(glibc ≥ 2.17)
Linux i686
(glibc ≥ 2.12)
macOS universal2 Windows x86_64
3.14 ✅ ✅ ✅ (macOS ≥ 10.14) ✅
3.13 ✅ ✅ ✅ (macOS ≥ 10.14) ✅
3.12 ✅ ✅ ✅ (macOS ≥ 10.14) ✅
3.11 ✅ ✅ ✅ (macOS ≥ 10.9) ✅
3.10 ✅ ✅ ✅ (macOS ≥ 10.9) ✅

Notes:

  • ✅ = Built and available
  • ❌ = Not built
  • macOS universal2 = Supports both ARM64 and x86-64 architectures

Building on Windows (local)

To reproduce the Windows CI build locally and debug failures:

  1. Install MSYS2 (e.g. from msys2.org), then in an MSYS2 UCRT64 shell install dependencies:

    pacman -S mingw-w64-ucrt-x86_64-gcc mingw-w64-ucrt-x86_64-pkg-config \
      mingw-w64-ucrt-x86_64-glib2 mingw-w64-ucrt-x86_64-gmp \
      mingw-w64-ucrt-x86_64-readline mingw-w64-ucrt-x86_64-sqlite3 \
      mingw-w64-ucrt-x86_64-libpng mingw-w64-ucrt-x86_64-gettext
    
  2. In PowerShell (from the repo root), run the build script (same steps as .github/actions/build-wheel on windows-latest):

    .\scripts\build-windows-local.ps1
    

    This runs meson setup / meson compile only. To also build wheels with cibuildwheel:

    .\scripts\build-windows-local.ps1 -Wheel
    

    If MSYS2 is not in C:\msys64, set $env:MSYS2_ROOT before running (e.g. $env:MSYS2_ROOT = "D:\msys64").

Testing

The gnubg package has basic unit testing. After installation, run:

python3 -m unittest discover -s gnubg.tests

AI-Assisted Development

Parts of this project were developed with the assistance of generative AI tools.

Specifically, the following models were used:

  • GPT-4o (OpenAI ChatGPT)
  • o4-mini-high (OpenAI ChatGPT)

These models were used to assist with code generation, documentation drafting, and architectural guidance. All outputs were reviewed and curated by a human before inclusion.

⚠️ Disclaimer:
Although human-reviewed, some AI-generated content may contain mistakes, inaccuracies, or outdated practices. Contributors and users should critically assess all code, comments, and documentation. We welcome corrections and improvements via pull requests or issues.

Code of Conduct

Please read the Code of Conduct to learn how to interact positively.

Contributing

Your expertise and enthusiasm are welcome! You can contribute by:

  • Reviewing and testing pull requests
  • Reporting and triaging issues
  • Improving documentation, tutorials, and examples
  • Enhancing engine parameters or submodules
  • Maintaining website or branding assets
  • Translating materials
  • Assisting with outreach and onboarding
  • Writing grant proposals or helping with fundraising

For more information, see our Contributing Guide. If you’re unsure where to start, open an issue or join the discussion on our mailing list!

Acknowledgments

This project builds upon the extensive work of the GNU Backgammon (GNUBG) community. Specifically the pygnubg program developed by Joseph Heled.

We express our gratitude to all contributors who have dedicated their time and expertise to the development of GNUBG.

  • AUTHORS.md: A list of primary contributors to the gnubg project can be found here.
  • GNUBG credits.sh: For a comprehensive list of contributors to the core GNUBG project, please refer to the credits.sh file.

We also thank the broader GNUBG community, including testers, translators, and mailing list participants, for their invaluable support.

Metadata

Release files for gnubg 1.1.0a17

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

Built distributions (wheels)

Table of built distributions (wheels) for gnubg 1.1.0a17
File Actions
gnubg-1.1.0a17-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for gnubg-1.1.0a17-cp313-cp313-win_amd64.whl
gnubg-1.1.0a17-cp313-cp313-musllinux_1_2_x86_64.whl CPython 3.13 CPython 3.13 Linux musl 1.2+ x86-64 Details for gnubg-1.1.0a17-cp313-cp313-musllinux_1_2_x86_64.whl
gnubg-1.1.0a17-cp313-cp313-manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64 Details for gnubg-1.1.0a17-cp313-cp313-manylinux_2_28_x86_64.whl
gnubg-1.1.0a17-cp313-cp313-macosx_15_0_arm64.whl CPython 3.13 CPython 3.13 macOS 15.0+ ARM64 Details for gnubg-1.1.0a17-cp313-cp313-macosx_15_0_arm64.whl
gnubg-1.1.0a17-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for gnubg-1.1.0a17-cp312-cp312-win_amd64.whl
gnubg-1.1.0a17-cp312-cp312-musllinux_1_2_x86_64.whl CPython 3.12 CPython 3.12 Linux musl 1.2+ x86-64 Details for gnubg-1.1.0a17-cp312-cp312-musllinux_1_2_x86_64.whl
gnubg-1.1.0a17-cp312-cp312-manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64 Details for gnubg-1.1.0a17-cp312-cp312-manylinux_2_28_x86_64.whl
gnubg-1.1.0a17-cp312-cp312-macosx_15_0_arm64.whl CPython 3.12 CPython 3.12 macOS 15.0+ ARM64 Details for gnubg-1.1.0a17-cp312-cp312-macosx_15_0_arm64.whl
gnubg-1.1.0a17-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for gnubg-1.1.0a17-cp311-cp311-win_amd64.whl
gnubg-1.1.0a17-cp311-cp311-musllinux_1_2_x86_64.whl CPython 3.11 CPython 3.11 Linux musl 1.2+ x86-64 Details for gnubg-1.1.0a17-cp311-cp311-musllinux_1_2_x86_64.whl
gnubg-1.1.0a17-cp311-cp311-manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64 Details for gnubg-1.1.0a17-cp311-cp311-manylinux_2_28_x86_64.whl
gnubg-1.1.0a17-cp311-cp311-macosx_15_0_arm64.whl CPython 3.11 CPython 3.11 macOS 15.0+ ARM64 Details for gnubg-1.1.0a17-cp311-cp311-macosx_15_0_arm64.whl
gnubg-1.1.0a17-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for gnubg-1.1.0a17-cp310-cp310-win_amd64.whl
gnubg-1.1.0a17-cp310-cp310-musllinux_1_2_x86_64.whl CPython 3.10 CPython 3.10 Linux musl 1.2+ x86-64 Details for gnubg-1.1.0a17-cp310-cp310-musllinux_1_2_x86_64.whl
gnubg-1.1.0a17-cp310-cp310-manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.28+ x86-64 Details for gnubg-1.1.0a17-cp310-cp310-manylinux_2_28_x86_64.whl
gnubg-1.1.0a17-cp310-cp310-macosx_15_0_arm64.whl CPython 3.10 CPython 3.10 macOS 15.0+ ARM64 Details for gnubg-1.1.0a17-cp310-cp310-macosx_15_0_arm64.whl

Total release size: 190.4 MB

Release files / gnubg-1.1.0a17-cp313-cp313-win_amd64.whl

Download URL gnubg-1.1.0a17-cp313-cp313-win_amd64.whl
Size 12.8 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
2ae92df7279fad7e8b1f4f768c231a52c064cc0203cf00379bbeeca38eb656b9
BLAKE2b-256 checksum
How to use checksums
e9045552f6ba799bb49aa667064879695e86aec066dc4895962b632cfe9ce160
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / gnubg-1.1.0a17-cp313-cp313-musllinux_1_2_x86_64.whl

Download URL gnubg-1.1.0a17-cp313-cp313-musllinux_1_2_x86_64.whl
Size 11.8 MB
Tags CPython 3.13 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
4be7887121231aaf3cb38e65e919ec1caad4245bfade35ab4ad433704ed77c82
BLAKE2b-256 checksum
How to use checksums
383a2b331b9a0912af5b368bbf5122c172346a1515d1ecc6d4a9309ff3249fd2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / gnubg-1.1.0a17-cp313-cp313-manylinux_2_28_x86_64.whl

Download URL gnubg-1.1.0a17-cp313-cp313-manylinux_2_28_x86_64.whl
Size 12.8 MB
Tags CPython 3.13 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
7ca2b1ac76756779ad62c1e78abe2f0c5ffd8c98aef72a8a9f76089589baf57d
BLAKE2b-256 checksum
How to use checksums
34e094105e66857ca673fc3bc35f41088fb7775c93efc783704474ae573ac2c5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / gnubg-1.1.0a17-cp313-cp313-macosx_15_0_arm64.whl

Download URL gnubg-1.1.0a17-cp313-cp313-macosx_15_0_arm64.whl
Size 10.2 MB
Tags CPython 3.13 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
c7e3618fa9a2e4db0601ee5fb75af8a1c4a63984b47639a511f429b7078993c9
BLAKE2b-256 checksum
How to use checksums
065f4ede8b0be457cd186269a345a71932181355380072cfa8df8bb95c697aff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / gnubg-1.1.0a17-cp312-cp312-win_amd64.whl

Download URL gnubg-1.1.0a17-cp312-cp312-win_amd64.whl
Size 12.8 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
d6ed2c39b6fe786ea11fdcb6fcf4e01bccce8457c5bd831c5802c100f3e3fb31
BLAKE2b-256 checksum
How to use checksums
9525f4c955c0009b11e10addad85a50bc6ec358df917b5c09f21c44ef653dbfe
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / gnubg-1.1.0a17-cp312-cp312-musllinux_1_2_x86_64.whl

Download URL gnubg-1.1.0a17-cp312-cp312-musllinux_1_2_x86_64.whl
Size 11.8 MB
Tags CPython 3.12 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
5930b5efb430036efbfbcbcf2ea744d406409375c96a3afb3ab3f874a4bd30ec
BLAKE2b-256 checksum
How to use checksums
776430a8bfbb393a82c70cd221467d301634ab3ffce6182f4ebdaafa057ab4ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / gnubg-1.1.0a17-cp312-cp312-manylinux_2_28_x86_64.whl

Download URL gnubg-1.1.0a17-cp312-cp312-manylinux_2_28_x86_64.whl
Size 12.8 MB
Tags CPython 3.12 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
ec719c52d745535a19cce836ed81821a20b30a57943ea1b25cf0cd08516d3fc2
BLAKE2b-256 checksum
How to use checksums
d5b7d2e8bc5fa44fbf71e6dc06ff52c7fc9c68e6f0a8f466a36abbc417f226e7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / gnubg-1.1.0a17-cp312-cp312-macosx_15_0_arm64.whl

Download URL gnubg-1.1.0a17-cp312-cp312-macosx_15_0_arm64.whl
Size 10.2 MB
Tags CPython 3.12 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
1595fb0a4b0beb73ac5f70aab1d31724ff4ddcb6adf03127ff8a4561f1681609
BLAKE2b-256 checksum
How to use checksums
eedc0ad13167aabfbcb7b8f61be3c4fe1cb8c2fdf7f2ab9c6f534a47c4a0ce59
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / gnubg-1.1.0a17-cp311-cp311-win_amd64.whl

Download URL gnubg-1.1.0a17-cp311-cp311-win_amd64.whl
Size 12.8 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
4cf06d441d78f4b55ef652b24a2894a74ab3ef8b064b2f3f325d915af8a0ffb3
BLAKE2b-256 checksum
How to use checksums
64e8690bb391b3988fb1b9f6cd22ebe52375bff8147f4f8fbba087d144db1f14
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / gnubg-1.1.0a17-cp311-cp311-musllinux_1_2_x86_64.whl

Download URL gnubg-1.1.0a17-cp311-cp311-musllinux_1_2_x86_64.whl
Size 11.8 MB
Tags CPython 3.11 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
75e98e636f844c5ba0db6a1a7dd1241301450d79450f1132e5020c0e18eae6b7
BLAKE2b-256 checksum
How to use checksums
a393533f27fb68aeab228f59a1792819dc4ca22d44ff6ad37b9b8ec6fbb9dbcb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / gnubg-1.1.0a17-cp311-cp311-manylinux_2_28_x86_64.whl

Download URL gnubg-1.1.0a17-cp311-cp311-manylinux_2_28_x86_64.whl
Size 12.8 MB
Tags CPython 3.11 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
362c365f14120e5ba39bc14ef8744106e402437ad3fc1ce978d7480959378437
BLAKE2b-256 checksum
How to use checksums
4a4940bfffbaba4ef1c98dc33d297c1a79dd7dc02e95a4cc8b6cdd7327cd50a4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / gnubg-1.1.0a17-cp311-cp311-macosx_15_0_arm64.whl

Download URL gnubg-1.1.0a17-cp311-cp311-macosx_15_0_arm64.whl
Size 10.2 MB
Tags CPython 3.11 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
91863ff46f8b8fd88be96b23d8a326141370394d08e3113fabfe01bb3868171c
BLAKE2b-256 checksum
How to use checksums
fa659c303c94cc94295df295f2f9e3c970e04cb3b63d91c5d80822b9fd7dd8bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / gnubg-1.1.0a17-cp310-cp310-win_amd64.whl

Download URL gnubg-1.1.0a17-cp310-cp310-win_amd64.whl
Size 12.8 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
2a626c866b97e5d5e2a23d1936480362076b91a8fb12bdaac3c05afab09e2294
BLAKE2b-256 checksum
How to use checksums
f54cac943d35f58ffbd72c304cdea2da87b9cdf76ca0ee5f75705160326229d3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Release files / gnubg-1.1.0a17-cp310-cp310-musllinux_1_2_x86_64.whl

Download URL gnubg-1.1.0a17-cp310-cp310-musllinux_1_2_x86_64.whl
Size 11.8 MB
Tags CPython 3.10 Linux musl 1.2+ x86-64
SHA-256 checksum
How to use checksums
92686d597e5a6565de3f9013f8f35205fa730dca080327b5b7b3c7ccd5a78d9a
BLAKE2b-256 checksum
How to use checksums
a2ff57d6625111ab5d06ce86cbed8bc88ad4b06297362967f08a13d507dd6b6d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / gnubg-1.1.0a17-cp310-cp310-manylinux_2_28_x86_64.whl

Download URL gnubg-1.1.0a17-cp310-cp310-manylinux_2_28_x86_64.whl
Size 12.8 MB
Tags CPython 3.10 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
6cee4e72aa6172ed73f2951cd6a7c6b9c6910140f7bda8fbf63a2182e029674a
BLAKE2b-256 checksum
How to use checksums
6e41544f74b937a278cdfe0777f0b747755fb23436f187404220f4031d026fd5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.18

Release files / gnubg-1.1.0a17-cp310-cp310-macosx_15_0_arm64.whl

Download URL gnubg-1.1.0a17-cp310-cp310-macosx_15_0_arm64.whl
Size 10.2 MB
Tags CPython 3.10 macOS 15.0+ ARM64
SHA-256 checksum
How to use checksums
d9863d0a39e57f43e1da580efc53efcf68d01c207e0bbb228a9057b9f6ad5063
BLAKE2b-256 checksum
How to use checksums
c6eba576273efd36008503d384c4f271afc9d5388df1efb7f150504ce7fef2ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.17

Security for gnubg 1.1.0a17

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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