Skip to main content

bridge-solver

Contract bridge analysis for Python:

  • a fast double-dummy solver: the full table of tricks for every declarer and strain;
  • par scoring;
  • card-by-card play analysis, with what each card played cost;
  • a claim checker. It decides whether a claim holds however the unseen cards lie, not just double dummy, the way BBO's checker does. It handles claims by declarer and by a defender.

It's the engine behind the bridge-solver project. It's written in Rust and comes as a prebuilt wheel for Linux, macOS and Windows, so there's nothing to compile.

pip install bridge-solver

Quick start

import bridge_solver as bs

deal = "N:AKQT3.J6.KJ42.95 652.AK42.AQ87.T4 J74.QT95.T.AK863 98.873.9653.QJ72"

bs.dd_table(deal)["N"]          # {'C': 8, 'D': 7, 'H': 8, 'S': 10, 'NT': 9}
bs.par(deal, "None")            # {'score_ns': 420, 'optimum_score': 'NS 420', 'par_contract': 'NS 4S='}

# North declares 4S. East has cashed the HA and HK. Can East claim a third
# trick with the DA? Not as far as East can see: declarer may be void in
# diamonds and ruff.
plays = "HA H5 H3 H6 HK H9 H7 HJ"
bs.check_claim(deal, "S", "N", 3, plays=plays, claimer="E")["verdict"]   # 'invalid'
bs.max_claim(deal, "S", "N", plays=plays, claimer="E")["guaranteed"]     # 2

Conventions

  • Deals are PBN: "N:<north> <east> <south> <west>". Each hand is spades.hearts.diamonds.clubs, e.g. "AKQT3.J6.KJ42.95".
  • Seats are "N", "E", "S", "W".
  • Strains are "C", "D", "H", "S", "NT".
  • Cards are a suit letter then a rank: "SA", "HT".
  • Plays start with the opening lead. Pass them as a list (["HA", "H5"]) or as one string ("HA H5"). The leader defaults to declarer's left-hand opponent.
  • Errors: anything the solver can't use raises bridge_solver.BridgeSolverError, a ValueError.
  • Threads: every call releases the GIL while it computes, so threads solve in parallel.

Reference

Function Returns
dd_table(deal) {seat: {strain: tricks}}, the tricks each seat takes as declarer
par(deal, vulnerable="None") par score and contracts; vulnerable is "None", "NS", "EW" or "All"
solve(deal, trump, leader) North-South's double-dummy tricks with leader on lead
check_claim(deal, trump, declarer, tricks, *, plays, leader, claimer, budget) {"verdict": "valid"/"invalid"/"undecided", ...}
max_claim(deal, trump, declarer, *, plays, leader, claimer, budget) {"guaranteed": n, "undecided": bool, ...}
PlayAnalyzer().trace(deal, trump, declarer, plays) every card played, with its double-dummy cost
PlayAnalyzer().alternatives(deal, trump, declarer, plays, card) every card that could have been played there, with its cost
PlayAnalyzer().optimal_line(deal, trump, declarer, plays, start) a double-dummy-perfect continuation

Claims

  • tricks is a total for the whole hand. In check_claim it's the claiming side's total, counting tricks already won, as BBO shows it.
  • What "valid" means. A claim is valid only if the claimer has a line that wins those tricks against every layout of the cards they can't see. Declarer sees their own hand and dummy. A defender sees their own hand and dummy, and their claim must also work whatever partner holds and however partner plays.
  • The node budget. The search has a budget, 2,000,000 nodes by default. When it runs out the verdict is "undecided"; treat that as rejected, as BBO does. Typical claims settle in about a millisecond.
  • Both sides. max_claim gives the most tricks the claimer's side is sure of. Call it once with declarer and once with a defender as claimer.

How the checker works, and why: design notes. You can time it in your browser on the benchmark page, and try claims on your own hands on the claim checker page.

Licence

MIT OR Apache-2.0. The double-dummy search is a port of Hanhong Xue's bridge-solver. See the repository for full attribution.

Metadata

Release files for bridge-solver 2.3.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 bridge-solver 2.3.0
File Size Uploaded Provenance Actions
bridge_solver-2.3.0.tar.gz 639.4 kB With provenance Details for bridge_solver-2.3.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for bridge-solver 2.3.0
File Actions
bridge_solver-2.3.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for bridge_solver-2.3.0-cp39-abi3-win_amd64.whl
bridge_solver-2.3.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for bridge_solver-2.3.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
bridge_solver-2.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for bridge_solver-2.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
bridge_solver-2.3.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for bridge_solver-2.3.0-cp39-abi3-macosx_11_0_arm64.whl
bridge_solver-2.3.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for bridge_solver-2.3.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 3.0 MB

Release files / bridge_solver-2.3.0.tar.gz

Download URL bridge_solver-2.3.0.tar.gz
Size 639.4 kB
Tags Source
SHA-256 checksum
How to use checksums
c4b4cddd2d883d3367fecbe148aba66d2cc128ff7d6837ae87648a5fe98382cd
BLAKE2b-256 checksum
How to use checksums
10236646cb82966da1dbbae4b47e766c8c5e122cda00bc848a7eaae2b55d08bd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / bridge_solver-2.3.0-cp39-abi3-win_amd64.whl

Download URL bridge_solver-2.3.0-cp39-abi3-win_amd64.whl
Size 379.9 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
a9e36185c241485150b5fd0061e1b09bb8294736612cb089badd8b63b0d80016
BLAKE2b-256 checksum
How to use checksums
f10b6e48e9ac89cab8858e94d620d83384c2af8cbe07814f332ab238d9cf4e11
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / bridge_solver-2.3.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL bridge_solver-2.3.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 540.6 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
8a27e8919774aed8a2bf60a01e2c22003053ec5430a76d7137056867be653d93
BLAKE2b-256 checksum
How to use checksums
8201a25c37a0e7425ab63d69baa0d2d54761bff3d55a7277db88cd0ca7ac294d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / bridge_solver-2.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL bridge_solver-2.3.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 519.2 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
28141cc016dd3b57a52de8546ee755fb682e17a04bedcdd6a81e9655fec9e341
BLAKE2b-256 checksum
How to use checksums
5845b674ff2c4cb39fbc822311df2e87639b4c3feac22a9872e352894774bce7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / bridge_solver-2.3.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL bridge_solver-2.3.0-cp39-abi3-macosx_11_0_arm64.whl
Size 476.9 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3bce2d4642d929db75bd3b5a3cc119efda0b924f8cc4a590e57ee694de2a3d28
BLAKE2b-256 checksum
How to use checksums
978f00ca2e01ef4c8a0d11538887e155ae60d3af99e881c17106e1ab07819a83
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Release files / bridge_solver-2.3.0-cp39-abi3-macosx_10_12_x86_64.whl

Download URL bridge_solver-2.3.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 488.8 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
36bdec6ed1d78ac189a0b51d6753cf5d2c0bc67db590bcd3b28a98e70cbc2c45
BLAKE2b-256 checksum
How to use checksums
c3a24257213c40e680fc0dfc8922a931b6569a23868ac3894eeae71c9f22e20c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

Security for bridge-solver 2.3.0

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.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for bridge_solver-2.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 22, 2026.

Transparency log

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