skillfed

cmdstanpy

Python interface to CmdStan

cmdstanpy v1.3.0 7.0M downloads/30d#1,800 on PyPI199
Permissive license BSD-3-Clause Active released

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 cmdstanpy

uv

uv add cmdstanpy

poetry

poetry add cmdstanpy

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: Science/ResearchLicense :: OSI Approved :: BSD LicenseNatural Language :: EnglishOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 3Topic :: Scientific/Engineering :: Information Analysis

Tags

bayesian inference pythonstan interface cmdstanprobabilistic programmingmcmc sampling pythonposterior sampling stanbayesian modelingstatistical inference cmdstan
bayesian-inferenceprobabilistic-programmingmcmc

More Information Analysis packages