cmdstanpy
Python interface to CmdStan
What it is and what it does
CmdStanPy is a lightweight wrapper around CmdStan, the command-line interface to the Stan probabilistic programming language. It lets you write statistical models in Stan's modeling language, compile them to executables, and run Bayesian inference—MCMC sampling, variational inference, and optimization—all from Python. The package handles model compilation, data passing, and result parsing, while keeping memory overhead low by default and storing output on a temporary filesystem during development.
The interface is designed for both iterative model development and production workflows. It depends on numpy and pandas for numerical operations and data handling, plus tqdm for progress tracking and stanio for I/O. Because it calls compiled Stan executables rather than embedding C++ directly, installation is straightforward and the package remains modular—you use CmdStanPy to generate posterior samples, then use other tools for analysis and visualization.
Use it for:
- Fit Bayesian hierarchical models to experimental or observational data and extract posterior samples for inference.
- Develop and test Stan models iteratively during research, with automatic compilation and temporary output storage.
- Run multiple inference jobs across machines or clusters by scripting CmdStanPy to distribute analysis reproducibly.
- Compare inference algorithms (MCMC, variational, optimization) on the same model without rewriting code.
- Integrate Bayesian inference into Python data pipelines alongside pandas and numpy workflows.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
CmdStanPy provides a pure-Python interface to the Stan probabilistic programming language, enabling you to compile Stan models and run Bayesian inference algorithms without direct C++ interaction.
Yes. CmdStanPy is actively maintained, has no known vulnerabilities, minimal dependencies, and a permissive license. Install it if you need to run Stan models from Python for Bayesian inference, statistical modeling, or probabilistic programming. The low friction and modular design make it a solid choice for both research and production use.
Install
cmdstanpy on PyPI
pip
pip install cmdstanpyuv
uv add cmdstanpypoetry
poetry add cmdstanpyInstalling cmdstanpy
Before you install
Low friction: pure-Python wheel distribution with only four runtime dependencies (pandas, numpy, tqdm, stanio). Actively maintained with a recent release and ongoing repository activity.
License in practice
BSD-3-Clause permissive license allows commercial and private use with minimal restrictions; you must include the license text in distributions.
Quickstart
pip install cmdstanpy
from cmdstanpy import CmdStanModel
model = CmdStanModel(stan_file='model.stan')
fit = model.sample(chains=4, data=data_file)
Requires Python 3.9 or later; CmdStan itself (the underlying C++ compiler and inference engine) must be installed separately or will be downloaded on first use.
Verify before relying
- Whether CmdStan binaries are automatically downloaded and installed on first use, or if manual setup is required.
- Memory and disk footprint of compiled Stan models and posterior samples for typical use cases.
Package facts
| License | BSD-3-Clause (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 4 — pandas, numpy, tqdm, stanio |
| Maintenance | actively maintained — 298 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 6,992,043/month — #1,800 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: cmdstanpy-1.3.0-py3-none-any.whl
Tags
More Information Analysis packages
A drop-in replacement for Python's standard…
permissive · top 100 on PyPI
pyarrowpyarrow provides Python bindings to Apache…
permissive · top 100 on PyPI
networkxNetworkX provides data structures and…
permissive · top 1,000 on PyPI
snowflake-connector-pythonConnects Python applications to Snowflake data…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
snowflake-snowpark-pythonSnowpark Python provides APIs to query and…
permissive · top 1,000 on PyPI
pystanPyStan provides a Python interface to Stan for…
permissive · top 5,000 on PyPI
stanioStanIO converts Python dictionaries to…
permissive · top 5,000 on PyPI
httpstanhttpstan provides an HTTP REST interface to the…
permissive · top 5,000 on PyPI
pymc3PyMC3 is a Python package for Bayesian…
permissive · top 15,000 on PyPI
nutpienutpie provides a fast NUTS sampler for…
permissive · top 15,000 on PyPI
pymcPyMC is a Python package for Bayesian…
permissive · top 5,000 on PyPI
numpyroNumPyro is a probabilistic programming library…
permissive · top 15,000 on PyPI
tensorflow-probabilityTensorFlow Probability provides probabilistic…
permissive · top 5,000 on PyPI
emceeemcee implements affine-invariant ensemble…
permissive · top 5,000 on PyPI
pgmpypgmpy provides data structures and algorithms…
unclear · top 5,000 on PyPI