Pylea
Discrete probabilistic programming in Python.
Pylea computes probabilities, expected values and probability mass functions in
probabilistic models in which every variable takes only finitely many values. A model is
written as a discrete probabilistic program (DPP): a Python function decorated with
@DPP, in which coin flips are drawn with flip and events are conditioned on with
observe.
Installation
pip install pylea
Pylea requires Python 3.12 or later. pip install "pylea[gpu]" also installs PyTorch,
for evaluation on a GPU, and pip install "pylea[search]" installs kahypar, optuna and
cmaes, which cotengra uses where installed when it searches for a contraction order for the
costliest programs (macOS and Linux only).
Example
A disease occurs in a fraction 10⁻⁴ of the population. A test for it is positive for 99% of the patients who have the disease and for 2% of those who do not. The probability that a patient has the disease, given one positive and one negative test result:
from pylea import DPP, Bool, flip, observe, prob
@DPP
def test(has_it: Bool) -> Bool:
positive_given_disease = flip(0.99) # true positive rate
positive_given_no_disease = flip(0.02) # false positive rate
return (has_it & positive_given_disease) | (~has_it & positive_given_no_disease)
@DPP
def has_disease() -> Bool:
x = flip(1e-4) # prevalence
observe(test(x) & ~test(x)) # one positive, one negative result
return x
print(prob(has_disease)) # 5.0512703945042225e-05
Documentation
https://benediktpeterseim.github.io/Pylea/
Licence
MIT; see LICENSE.
Metadata
Release files for pylea 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| pylea-0.1.1.tar.gz | 237.7 kB | With provenance | Details for pylea-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| pylea-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for pylea-0.1.1-py3-none-any.whl |
Total release size: 522.2 kB
Release files / pylea-0.1.1.tar.gz
| Download URL | pylea-0.1.1.tar.gz |
|---|---|
| Size | 237.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
72c30c5db503c4cc9ca1067ff1dc80d547446af06d24a31d9722301fc196b317
|
|
BLAKE2b-256 checksum How to use checksums |
84438029726cb52fa3cb4bee2f05353b0e493584e53956b2fcfc0aeca3666789
|
| 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 14, 2026.
Transparency logRelease files / pylea-0.1.1-py3-none-any.whl
| Download URL | pylea-0.1.1-py3-none-any.whl |
|---|---|
| Size | 284.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6cba65a04f22d77e92fe42c29b21c718a3e4ad0c6c076e6c5043a1adfdd7facb
|
|
BLAKE2b-256 checksum How to use checksums |
c8e5860de50e29cd096e2f6ae9eadfe8069fc0f30a437c6be14055e80cbe0828
|
| 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 14, 2026.
Transparency logSecurity for pylea 0.1.1
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
Both files in this release have been uploaded with provenance metadata.
Attestation for pylea-0.1.1.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 14, 2026.
Transparency logA 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.