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.

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.0a16

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.0a16
File Actions
gnubg-1.1.0a16-cp313-cp313-win_amd64.whl CPython 3.13 CPython 3.13 Windows x86-64 Details for gnubg-1.1.0a16-cp313-cp313-win_amd64.whl
gnubg-1.1.0a16-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.0a16-cp313-cp313-musllinux_1_2_x86_64.whl
gnubg-1.1.0a16-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.13 CPython 3.13 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for gnubg-1.1.0a16-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
gnubg-1.1.0a16-cp313-cp313-macosx_14_0_arm64.whl CPython 3.13 CPython 3.13 macOS 14.0+ ARM64 Details for gnubg-1.1.0a16-cp313-cp313-macosx_14_0_arm64.whl
gnubg-1.1.0a16-cp312-cp312-win_amd64.whl CPython 3.12 CPython 3.12 Windows x86-64 Details for gnubg-1.1.0a16-cp312-cp312-win_amd64.whl
gnubg-1.1.0a16-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.0a16-cp312-cp312-musllinux_1_2_x86_64.whl
gnubg-1.1.0a16-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.12 CPython 3.12 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for gnubg-1.1.0a16-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
gnubg-1.1.0a16-cp312-cp312-macosx_14_0_arm64.whl CPython 3.12 CPython 3.12 macOS 14.0+ ARM64 Details for gnubg-1.1.0a16-cp312-cp312-macosx_14_0_arm64.whl
gnubg-1.1.0a16-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details for gnubg-1.1.0a16-cp311-cp311-win_amd64.whl
gnubg-1.1.0a16-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.0a16-cp311-cp311-musllinux_1_2_x86_64.whl
gnubg-1.1.0a16-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.28+ x86-64, Linux glibc 2.24+ x86-64 Details for gnubg-1.1.0a16-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
gnubg-1.1.0a16-cp311-cp311-macosx_14_0_arm64.whl CPython 3.11 CPython 3.11 macOS 14.0+ ARM64 Details for gnubg-1.1.0a16-cp311-cp311-macosx_14_0_arm64.whl
gnubg-1.1.0a16-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details for gnubg-1.1.0a16-cp310-cp310-win_amd64.whl
gnubg-1.1.0a16-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.0a16-cp310-cp310-musllinux_1_2_x86_64.whl
gnubg-1.1.0a16-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.24+ x86-64, Linux glibc 2.28+ x86-64 Details for gnubg-1.1.0a16-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
gnubg-1.1.0a16-cp310-cp310-macosx_14_0_arm64.whl CPython 3.10 CPython 3.10 macOS 14.0+ ARM64 Details for gnubg-1.1.0a16-cp310-cp310-macosx_14_0_arm64.whl

Total release size: 178.2 MB

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

Download URL gnubg-1.1.0a16-cp313-cp313-win_amd64.whl
Size 12.9 MB
Tags CPython 3.13 Windows x86-64
SHA-256 checksum
How to use checksums
ff2ee23d1b408e5978408a96abf0d36e325d5b1f2b2e9bbf0f394230bc58899b
BLAKE2b-256 checksum
How to use checksums
25469c8fce1888da18a915fceffcf01640a67300d02d3bb071d4e1209287d25f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

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

Download URL gnubg-1.1.0a16-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
e683c1db5d076a75a1a0d747004cb8c936dca9051ca01d09aa928f5d87d5fb21
BLAKE2b-256 checksum
How to use checksums
477f2de46a53b9461b6f9c337547c9e67efe4dc17f5a19f661e83b364ed9e284
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / gnubg-1.1.0a16-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL gnubg-1.1.0a16-cp313-cp313-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.7 MB
Tags CPython 3.13 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
900f8b512a5689b0e26153caf98fd6a5914a4e4114890f84ef3b0e22f267973a
BLAKE2b-256 checksum
How to use checksums
f6426f447672f8b96f6893c1b4436b5f3809c90ce72274632f3a50cfeb7169f2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / gnubg-1.1.0a16-cp313-cp313-macosx_14_0_arm64.whl

Download URL gnubg-1.1.0a16-cp313-cp313-macosx_14_0_arm64.whl
Size 10.1 MB
Tags CPython 3.13 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
3209723d96127cf6e552c039415ce37eb70942115b9dd636643b060e07b5cb4c
BLAKE2b-256 checksum
How to use checksums
688dc296d5695a3c0300d5393df52a02a963755b430f51228d5a4d714f1f59eb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL gnubg-1.1.0a16-cp312-cp312-win_amd64.whl
Size 12.9 MB
Tags CPython 3.12 Windows x86-64
SHA-256 checksum
How to use checksums
636fc8f53ef5022cdc83e54446382b72ba3c39a29c132fbf15d1da1395c8842c
BLAKE2b-256 checksum
How to use checksums
c4ffb531319322da1f37521fa1d9a7ba7094a32812a227bd85b001d8d333bd4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

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

Download URL gnubg-1.1.0a16-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
562420da3124915e2bb9fba69e5c35e48494791b58d4455522e3901f090c3129
BLAKE2b-256 checksum
How to use checksums
a3546cd19f5c1704cda0ad57618d05035758ac6e86a0cee44e5b903689e9bd42
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / gnubg-1.1.0a16-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL gnubg-1.1.0a16-cp312-cp312-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.7 MB
Tags CPython 3.12 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
86cb81b3c6018bf22ca0777dcf61e9e0131ec9d9dc69323b03534590842167a7
BLAKE2b-256 checksum
How to use checksums
67d34cbaa14e684823fd08f9a219c04b75e86453d5a09041242809407959904f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / gnubg-1.1.0a16-cp312-cp312-macosx_14_0_arm64.whl

Download URL gnubg-1.1.0a16-cp312-cp312-macosx_14_0_arm64.whl
Size 10.1 MB
Tags CPython 3.12 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
874fab5c1fdee4b14728e354ae1b5a89fa106c5e5125fee5ec425fc650d67608
BLAKE2b-256 checksum
How to use checksums
28e960220b6d91ba136391f3a81d958a42422563c1b95c28106b778f453a76e6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL gnubg-1.1.0a16-cp311-cp311-win_amd64.whl
Size 12.9 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
c8b5ebfffeb679bfcb8f69c95ca1bee5208e7ec23d4ea7dd9b54270a9662d03b
BLAKE2b-256 checksum
How to use checksums
cd837e74f9a50e636a4f3b64e9009dac4fbe8916d384eff91444838ecf471b0f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

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

Download URL gnubg-1.1.0a16-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
091b8698ae183ded8a383a7b6b587e5621310ee523930032705b154d7c976142
BLAKE2b-256 checksum
How to use checksums
1f37c8b4c26b76ed9ef2d31546ab011d5c96c2210e42c3bdba567f27af4ea857
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / gnubg-1.1.0a16-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL gnubg-1.1.0a16-cp311-cp311-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.7 MB
Tags CPython 3.11 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
fb33058dba1f23114354b66988492b71b0ab44984d08f1dc918fb61cb6c256ac
BLAKE2b-256 checksum
How to use checksums
11e1cccc68bd8b9d9e4f24caefec6ae2a4ac2ea9cd29a76e654c97c833ef6365
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / gnubg-1.1.0a16-cp311-cp311-macosx_14_0_arm64.whl

Download URL gnubg-1.1.0a16-cp311-cp311-macosx_14_0_arm64.whl
Size 10.1 MB
Tags CPython 3.11 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
082f5f3f3ef106a0a78d5a0f6b0f55fe209f60ea5bc791b14061c3c44dd742ea
BLAKE2b-256 checksum
How to use checksums
9788a8beef5c9e1ae33eba76f1af2981465fc997080f0d535c9f5106439d7190
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

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

Download URL gnubg-1.1.0a16-cp310-cp310-win_amd64.whl
Size 12.9 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
166aeb71f75bc80c2dc0611dd5dd26f39bce9e7d5802c5a21c6b9d518c947aa2
BLAKE2b-256 checksum
How to use checksums
1012bf5d23d11bb58c2ca23f2c2b6ed9c4f2f9a2d938e16062410f268e4507e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

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

Download URL gnubg-1.1.0a16-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
9b8e3033f87586ff9f0bda6b1eaad0775f181f0b17f68aad9a1b4519890fee5f
BLAKE2b-256 checksum
How to use checksums
76d37a06860f7a0c7c4c47b8799538f8de25468356cb3efb6409e4a2249a78ec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / gnubg-1.1.0a16-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl

Download URL gnubg-1.1.0a16-cp310-cp310-manylinux_2_24_x86_64.manylinux_2_28_x86_64.whl
Size 9.7 MB
Tags CPython 3.10 Linux glibc 2.24+ x86-64 Linux glibc 2.28+ x86-64
SHA-256 checksum
How to use checksums
f6810a9ed22e21cc460e9063f0c0111d08493c9b562698617efb95d9d9362110
BLAKE2b-256 checksum
How to use checksums
ff5b7a26c70272ee372f66e84a03209336134173f718284d659f68ed370dc43f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.15

Release files / gnubg-1.1.0a16-cp310-cp310-macosx_14_0_arm64.whl

Download URL gnubg-1.1.0a16-cp310-cp310-macosx_14_0_arm64.whl
Size 10.1 MB
Tags CPython 3.10 macOS 14.0+ ARM64
SHA-256 checksum
How to use checksums
b0fb105ed07de93ed51109c73f09d847123e32ee7ae46f00b30d7759e7111f95
BLAKE2b-256 checksum
How to use checksums
50f149e417994d9b593847910e5baea6b6cc9c65476ee0ae23fde77061e7220c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.14

Security for gnubg 1.1.0a16

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