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.

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.1.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.1.0
File Size Uploaded Provenance Actions
bridge_solver-2.1.0.tar.gz 541.1 kB With provenance Details for bridge_solver-2.1.0.tar.gz

Built distributions (wheels)

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

Total release size: 2.8 MB

Release files / bridge_solver-2.1.0.tar.gz

Download URL bridge_solver-2.1.0.tar.gz
Size 541.1 kB
Tags Source
SHA-256 checksum
How to use checksums
8f4782c06ca1c11a170e583f6d744495f934d77cfbef510c5453b2b96c5b124e
BLAKE2b-256 checksum
How to use checksums
4ce37cfe2122e7dd9c12fb34635e96a295e0894220f7a75cf2331b792753c583
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 Oct 27, 2026.

Transparency log

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

Download URL bridge_solver-2.1.0-cp39-abi3-win_amd64.whl
Size 347.4 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
61060ba7372f8e9695b16439ebb5c354ea7c78b953ae939b5f445d756227d57a
BLAKE2b-256 checksum
How to use checksums
6a87a45eae1e205488e4924a242da11fae1c0f87858f655a08777fd1be7954bc
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 Oct 27, 2026.

Transparency log

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

Download URL bridge_solver-2.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 504.9 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
46bf85107f96e26d65a6653de26fe3c167c3fa38124bd699834865f1e8c41728
BLAKE2b-256 checksum
How to use checksums
39b6fd40826abcd8991716d8d50676baa9652221f82bade969550b7b8aef4ea9
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 Oct 27, 2026.

Transparency log

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

Download URL bridge_solver-2.1.0-cp39-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 491.6 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
af98f3050abe089af7a1eccf954477707bb5b480c89887600004ab9bbccc92fc
BLAKE2b-256 checksum
How to use checksums
da7558aef207bef006bee3404052b42a12823d1267ee4fbcf7cd90073bcbfa5e
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 Oct 27, 2026.

Transparency log

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

Download URL bridge_solver-2.1.0-cp39-abi3-macosx_11_0_arm64.whl
Size 446.8 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
958d0ade0b5c43e4d5288bf63a07049494bb33701a9aa622feb78b2e3c35194d
BLAKE2b-256 checksum
How to use checksums
59dedb2b2846e835e06df7fa967e5b808e4f81be3cf952fb2a50d1d0ddd8ad37
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 Oct 27, 2026.

Transparency log

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

Download URL bridge_solver-2.1.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 457.5 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
a56cdbd29c0fd30cb476494f69c95c3b6e8738488684b000baa04a1a5f3d9d29
BLAKE2b-256 checksum
How to use checksums
0824f3cf576cf63f79ef74e7c613c4583ee53fe2bfcc8853a0b9e5ecb2f2bf73
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 Oct 27, 2026.

Transparency log

Security for bridge-solver 2.1.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.1.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 Oct 27, 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