Skip to main content

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.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 pylea 0.1.0
File Size Uploaded Provenance Actions
pylea-0.1.0.tar.gz 235.1 kB With provenance Details for pylea-0.1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pylea 0.1.0
File Interpreter ABI Platform Actions
pylea-0.1.0-py3-none-any.whl Python 3 none any Details for pylea-0.1.0-py3-none-any.whl

Total release size: 516.5 kB

Release files / pylea-0.1.0.tar.gz

Download URL pylea-0.1.0.tar.gz
Size 235.1 kB
Tags Source
SHA-256 checksum
How to use checksums
f4357a4b7e46768596d112d6d5ce5876da20efb57263a259e080bd45f24cd6a4
BLAKE2b-256 checksum
How to use checksums
47106588301de56e8efdfade89737743569321609db1e0f11217c6584d3ba3c5
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 11, 2026.

Transparency log

Release files / pylea-0.1.0-py3-none-any.whl

Download URL pylea-0.1.0-py3-none-any.whl
Size 281.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
83969ccc523cc53e8db09c67c3d2dcb318eeb039b84a398d4f19c4b21c83a7e3
BLAKE2b-256 checksum
How to use checksums
5087e6a44505fcbff10626d111b89c0e31ee95d4f76b769fa03af709fd57c328
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 11, 2026.

Transparency log

Security for pylea 0.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

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pylea-0.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 Nov 11, 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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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