skillfed

pgmpy

Python Toolkit for Causal and Probabilistic Reasoning

pgmpy v1.1.2 957.9K downloads/30d#4,642 on PyPI3,313
License unclear 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) Active released

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 pgmpy

uv

uv add pgmpy

poetry

poetry add pgmpy

Installing 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

Intended Audience :: EducationIntended Audience :: Science/ResearchOperating System :: MacOSOperating System :: Microsoft :: WindowsOperating System :: UnixProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Topic :: Scientific/EngineeringTopic :: Scientific/Engineering :: Artificial IntelligenceTopic :: Scientific/Engineering :: Bio-Informatics

Tags

bayesian network inferencecausal discovery algorithmsprobabilistic graphical modelscausal inference do-calculusstructure learning from dataparameter estimation networkscounterfactual reasoning
causal-inferencegraphical-modelsprobabilistic-reasoning

More Scientific/Engineering packages