Skip to content

PyProbs

Get True or False from a probability, whether you write it as a float, a percentage or a fraction.

Get started User Guide

$ uv add pyprobs

PyProbs turns a probability into a decision. Ask for "25%" and roughly one call in four returns True. You can draw once, draw many times in a single call, or keep an instance around that remembers every result and counts them for you.

  • Any notation


    0.25, "25%", "1/4" and "0.25" all mean the same probability.

  • Quick or tracked


    Probability.prob() draws without any setup, while an instance's iprob() records a history you can count.

  • Typed


    Ships with type hints and is checked with mypy in strict mode.

  • No dependencies


    Pure Python, nothing else to install.

A quick look

>>> from pyprobs import Probability as pr
>>> pr.prob("50%", num=5)
[False, False, True, True, False]
>>> p = pr()
>>> p.iprob("3/4", 0.5, num=2)
[[True, False], [True, True]]
>>> p.count_values("all")
{True: 3, False: 1}