pgmpy
Python Toolkit for Causal and Probabilistic Reasoning
What it is and what it does
pgmpy is a Python toolkit for building and reasoning with causal and probabilistic graphical models. It implements data structures for DAGs, Bayesian networks, dynamic Bayesian networks, and structural equation models, along with algorithms for causal discovery, causal identification, probabilistic and causal inference, parameter estimation, model validation, and simulation.
The package provides a unified, composable API across algorithms and is scikit-learn compatible where applicable, allowing use in sklearn pipelines or as standalone tools. It handles discrete data, linear Gaussian data, and mixture models with arbitrary relationships. The library is actively maintained, supports Python 3.10 through 3.14, and depends on standard scientific Python libraries.
Use it for:
- Learn causal structure from observational data using algorithms like PC, then estimate parameters and make predictions.
- Compute posterior distributions conditioned on observed evidence in discrete or continuous Bayesian networks.
- Generate synthetic data under specified interventions or counterfactual scenarios using do-calculus.
- Validate whether a proposed causal structure is compatible with observed data using metrics.
- Build hybrid models mixing discrete and continuous variables with functional relationships.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
pgmpy provides data structures and algorithms for causal discovery, causal inference, probabilistic inference, parameter learning, and model validation across Bayesian networks, DAGs, and structural equation models.
Yes. pgmpy is actively maintained, has low install friction, carries no security vulnerabilities, and offers a comprehensive toolkit for causal and probabilistic reasoning with a scikit-learn-compatible API. It is suitable for research, education, and production use in causal inference and graphical modeling tasks. The MIT license imposes no restrictions.
Install
pgmpy on PyPI
pip
pip install pgmpyuv
uv add pgmpypoetry
poetry add pgmpyInstalling pgmpy
Before you install
Low install friction with a pure-Python wheel. Maintenance is active with a recent release and 3313 GitHub stars. Depends on 12 well-established scientific libraries including networkx, numpy, scipy, scikit-learn, pandas, and statsmodels.
License in practice
Licensed under MIT with no restrictions on commercial or private use, though license treatment is marked unclear in metadata.
Quickstart
pip install pgmpy
from pgmpy.example_models import load_model
from pgmpy.estimators import PC
discrete_bn = load_model("bnlearn/alarm")
alarm_df = discrete_bn.simulate(n_samples=100)
dag = PC(data=alarm_df).estimate(ci_test="chi_square", return_type="dag")
Requires Python 3.10 or later (supports up to 3.14). All 12 runtime dependencies must be installed.
Verify before relying
- Whether all 12 runtime dependencies are always required or if some are optional for specific use cases.
- Performance characteristics or scalability limits for large graphical models.
- Whether torch backend support (mentioned in examples) requires additional optional dependencies.
Package facts
| License | The MIT License (MIT) Copyright (c) 2013 - present, pgmpy Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the… (full text in the JSON record) (unclear) |
| Python support | supports the current Python release (<3.15,>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 12 — huggingface_hub, networkx, numpy, scipy, scikit-learn, pandas, statsmodels, tqdm, pyparsing, joblib, opt_einsum, scikit-base |
| Maintenance | actively maintained — 106 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 957,860/month — #4,642 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pgmpy-1.1.2-py3-none-any.whl
Tags
More Scientific/Engineering packages
NumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
pandaspandas provides fast, flexible data structures…
permissive · top 100 on PyPI
scipyscipy provides numerical algorithms for…
permissive · top 100 on PyPI
scikit-learnscikit-learn provides a comprehensive Python…
permissive · top 1,000 on PyPI
dilldill extends Python's pickle module to…
permissive · top 1,000 on PyPI
multiprocessMultiprocess is an enhanced fork of Python's…
permissive · top 1,000 on PyPI
pyAgrum-nightlypyAgrum is a Python library for creating,…
unclear · top 15,000 on PyPI
pyjptpyjpt learns and reasons about joint…
unclear · top 15,000 on PyPI
dowhyDoWhy is a Python library for causal inference…
permissive · top 15,000 on PyPI
problogProbLog is a probabilistic logic programming…
permissive · top 15,000 on PyPI
causallibCausallib estimates causal effects from…
permissive · top 5,000 on PyPI
causalmlCausalml estimates the causal impact of…
permissive · top 15,000 on PyPI
pymcPyMC is a Python package for Bayesian…
permissive · top 5,000 on PyPI
tensorflow-probabilityTensorFlow Probability provides probabilistic…
permissive · top 5,000 on PyPI
pymc3PyMC3 is a Python package for Bayesian…
permissive · top 15,000 on PyPI
google-meridianMeridian is a Bayesian marketing mix modeling…
unclear · top 15,000 on PyPI