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.2.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.2.0
File Size Uploaded Provenance Actions
bridge_solver-2.2.0.tar.gz 623.4 kB With provenance Details for bridge_solver-2.2.0.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for bridge-solver 2.2.0
File Actions
bridge_solver-2.2.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for bridge_solver-2.2.0-cp39-abi3-win_amd64.whl
bridge_solver-2.2.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.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
bridge_solver-2.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for bridge_solver-2.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
bridge_solver-2.2.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for bridge_solver-2.2.0-cp39-abi3-macosx_11_0_arm64.whl
bridge_solver-2.2.0-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for bridge_solver-2.2.0-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 3.0 MB

Release files / bridge_solver-2.2.0.tar.gz

Download URL bridge_solver-2.2.0.tar.gz
Size 623.4 kB
Tags Source
SHA-256 checksum
How to use checksums
4f7e113812c8b8627448c626b6565028f1230e0c9f735ef24ce3f4c245ae3582
BLAKE2b-256 checksum
How to use checksums
d1c513f69d583f52597d9b0c091652e5354c21d9b624cc1ee84e880f7689f4ef
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 19, 2026.

Transparency log

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

Download URL bridge_solver-2.2.0-cp39-abi3-win_amd64.whl
Size 380.3 kB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
eefc1299a0a3d3caf4126ade5b5d19db03a52feb93972067a78cf76d7bb5a774
BLAKE2b-256 checksum
How to use checksums
653d717396937c3dee027fa5c5fec889b918723265e151571faa119a8130d213
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 19, 2026.

Transparency log

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

Download URL bridge_solver-2.2.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 539.8 kB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
62337e163b9bd7ecc53875df786571a0490ca0bddf2090710c3473c8462df399
BLAKE2b-256 checksum
How to use checksums
56bc9da721fc93e10ecc2bc532bd8ff9eac721cf12ede60da6f417f02150b2f6
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 19, 2026.

Transparency log

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

Download URL bridge_solver-2.2.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 518.8 kB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
f8bb79025066a41f0fbca32a324268b073647dc04f1332082922c2bb2045ff56
BLAKE2b-256 checksum
How to use checksums
898885bd63979aa20820270f2563c22ee7a6c5692e16426b5724bef3c9e4d0f5
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 19, 2026.

Transparency log

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

Download URL bridge_solver-2.2.0-cp39-abi3-macosx_11_0_arm64.whl
Size 478.6 kB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
3178fd7911fc0b1970dc3104c7d6b1bc12102df5a58e1a2954a9d1a7c6e943bc
BLAKE2b-256 checksum
How to use checksums
ece379b7bd3f1524ec4f5c0f51576883fd9daa5333cc230e6a71ca592b6e7d92
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 19, 2026.

Transparency log

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

Download URL bridge_solver-2.2.0-cp39-abi3-macosx_10_12_x86_64.whl
Size 491.0 kB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
fc4059f0260aca9a46e974e6854eb2f049d4b5d5487149e5f91011371d1af8bb
BLAKE2b-256 checksum
How to use checksums
9b466edc4c1eee9d2c53ffc2da0d312be201956c9b19ab2ae92e00f5b2bd83a3
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 19, 2026.

Transparency log

Security for bridge-solver 2.2.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.2.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 19, 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