CmdStanPy 1.0

Announcing version 1.0 of CmdStanPy!

CmdStanPy 1.0 is now available on Conda Forge: Cmdstanpy ::
and PyPi: cmdstanpy · PyPI

CmdStanPy provdes access to the Stan compiler, inference algorithms, and diagnostics.
It supports both development and production workflows and is well-suited for teaching and learning Stan.

Reasons to use CmdStanPy:

  1. Runs with latest Stan release
  2. Easy to install: CmdStanPy can automatically CmdStan and the underlying C++ toolchains
  3. Scalable: can fit big models and big datasets - if CmdStan can fit a model and dataset, so can CmdStanPy.
  4. Cross-platform: runs on Linux, macOS, and Windows.
  5. Non-restrictive license: BSD-3 license: cmdstanpy/ at develop · stan-dev/cmdstanpy · GitHub

Documentation: cmdstanpy – Python interface to CmdStan — CmdStanPy 1.0.0 documentation
GitHub repo: GitHub - stan-dev/cmdstanpy: CmdStanPy is a lightweight interface to Stan for Python users which provides the necessary objects and functions to compile a Stan program and fit the model to data using CmdStan.

Many thanks to all of our contributors - Contributors to stan-dev/cmdstanpy · GitHub - as well as to all users who’ve submitted feature requests and bug reports!


Thanks for the hard work on this. But now we have two python front-ends to Stan (pystan and cmdstanpy). Is there a summary of the differences and when we might prefer one or the other?

(I am mostly asking about the differences in the user experience, rather than their distinct back-end philosophies, although those are obviously related.)

Great question! I’ll do my best to summarize them:

CmdStanPy is essentially a wrapper for CmdStan, and PyStan (since version 3) is dependent on something called httpstan. I think there is some merit in comparing directly the features of CmdStan and httpstan:

  1. CmdStan is always available for the latest version of Stan. Ideally, CmdStan can update and there is no change needed in the wrappers (like CmdStanPy) before you can use it. httpstan needs to be updated alongside Stan.
  2. CmdStan is a file based interface. Inputs are written to JSON, and outputs are read from CSV. PyStan/httpstan works in memory with your model in the same process. There are advantages and disadvantages to both in terms of memory usage, IO speed, etc.
  3. Because httpstan works directly with the model in memory, it does have two features not available in CmdStan: the ability to evaluate the log probability function from within Python, and the ability to evaluate the gradient of the log probability function.
  4. But, CmdStan supports inference methods other than HMC sampling, (like MLE and variational inference) which httpstan does not.
  5. CmdStan is available on Windows, httpstan is not.

Those are the core differences in the feature set.

On the Python level, there are a few other differences, mostly around slightly different names or ways of structuring the API. CmdStanPy has a few more options for tweaking the compilation of the model and reading the output than PyStan, I believe.

If all you’re interested in is running HMC and then processing your output using something like pandas, both would be able to do that, but they offer different things around that.


I believe that way in which httpstan evaluates the gradient is not very efficient - @stevebronder would be able to give details.