Description
# CmdStanPy [](https://codecov.io/gh/stan-dev/cmdstanpy) CmdStanPy is a lightweight pure-Python interface to CmdStan which provides access to the Stan compiler and all inference algorithms. It supports both development and production workflows. Because model development and testing may require many iterations, the defaults favor development mode and therefore output files are stored on a temporary filesystem. Non-default options allow all aspects of a run to be specified so that scripts can be used to distributed analysis jobs across nodes and machines. CmdStanPy is distributed via PyPi: https://pypi.org/project/cmdstanpy/ or Conda Forge: https://anaconda.org/conda-forge/cmdstanpy ### Goals - Clean interface to Stan services so that CmdStanPy can keep up with Stan releases. - Provide access to all CmdStan inference methods. - Easy to install, + minimal Python library dependencies: numpy, pandas + Python code doesn't interface directly with c++, only calls compiled executables - Modular - CmdStanPy produces a MCMC sample (or point estimate) from the posterior; other packages do analysis and visualization. - Low memory overhead - by default, minimal memory used above that required by CmdStanPy; objects run CmdStan programs and track CmdStan input and output files. ### Source Repository CmdStanPy and CmdStan are available from GitHub: https://github.com/stan-dev/cmdstanpy and https://github.com/stan-dev/cmdstan ### Docs The latest release documentation is hosted on https://mc-stan.org/cmdstanpy, older release versions are available from readthedocs: https://cmdstanpy.readthedocs.io ### Licensing The CmdStanPy, CmdStan, and the core Stan C++ code are licensed under new BSD. ### Example ```python import os from cmdstanpy import cmdstan_path, CmdStanModel # specify locations of Stan program file and data stan_file = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan') data_file = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.data.json') # instantiate a model; compiles the Stan program by default model = CmdStanModel(stan_file=stan_file) # obtain a posterior sample from the model conditioned on the data fit = model.sample(chains=4, data=data_file) # summarize the results (wraps CmdStan `bin/stansummary`): fit.summary() ```
Release History
| Version | Changes | Urgency | Date |
|---|---|---|---|
| 1.3.0 | Imported from PyPI (1.3.0) | Low | 4/21/2026 |
| v1.3.0 | Please note that the next non-bugfix release of CmdStanPy will be CmdStanPy 2.0 and will remove existing deprecations ## New Features * Add `diagnose` method to `CmdStanModel`. by @tillahoffmann in https://github.com/stan-dev/cmdstanpy/pull/734 * add timing information for sampler outputs by @mitzimorris in https://github.com/stan-dev/cmdstanpy/pull/779 * Add new `create_inits()` methods to other stanfit classes by @amas0 in https://github.com/stan-dev/cmdstanpy/pull/791 ## Fixes | Low | 10/20/2025 |
| v1.2.4 | Please note that the next non-bugfix release of CmdStanPy will be CmdStanPy 2.0 and will remove existing deprecations ## Fixes * Add rebuild_cmdstan to API doc by @WardBrian in https://github.com/stan-dev/cmdstanpy/pull/761 * Fix from_csv failing to load files from CmdStan 2.35+ by @ahartikainen in https://github.com/stan-dev/cmdstanpy/pull/764 **Full Changelog**: https://github.com/stan-dev/cmdstanpy/compare/v1.2.3...v1.2.4 | Low | 6/17/2024 |
| v1.2.3 | Please note that the next non-bugfix release of CmdStanPy will be CmdStanPy 2.0 and will remove existing deprecations ## Fixes * Fix tests for CmdStan 2.35 by @WardBrian in https://github.com/stan-dev/cmdstanpy/pull/749 * Fix profile file output when running multiple chains in one process by @WardBrian in https://github.com/stan-dev/cmdstanpy/pull/751 **Full Changelog**: https://github.com/stan-dev/cmdstanpy/compare/v1.2.2...v1.2.3 | Low | 6/3/2024 |
| v1.2.2 | Please note that the next non-bugfix release of CmdStanPy will be CmdStanPy 2.0 and will remove existing deprecations ## Fixes * Update community.rst to mention `bibat` by @teddygroves in https://github.com/stan-dev/cmdstanpy/pull/737 * Move to pyproject.toml setup by @WardBrian in https://github.com/stan-dev/cmdstanpy/pull/735 * Extract format functionality from Model class by @WardBrian in https://github.com/stan-dev/cmdstanpy/pull/740 * Add a num_threads helper argument to pathfinder | Low | 3/26/2024 |
| v1.2.1 | Please note that the next non-bugfix release of CmdStanPy will be CmdStanPy 2.0 and will remove existing deprecations ## Fixes * Switch from np.random.RandomState to default_rng by @WardBrian in https://github.com/stan-dev/cmdstanpy/pull/712 * Fix minor doc typos by @gil2rok in https://github.com/stan-dev/cmdstanpy/pull/715 * Stan 2.34: Fix parsing of unit_e output files by @WardBrian in https://github.com/stan-dev/cmdstanpy/pull/723 * Add new Pathfinder arguments by @WardBrian in https | Low | 2/5/2024 |
| v1.2.0 | Please note that the next non-bugfix release of CmdStanPy will be CmdStanPy 2.0 and will remove existing deprecations ### New Features: * Allow git:TAG as a version in install_cmdstan. https://github.com/stan-dev/cmdstanpy/pull/679 * [Stan 2.32] Laplace method and other changes. https://github.com/stan-dev/cmdstanpy/pull/669 * Add "chain__", "iter__", and "draw__" columns to draws_pd. https://github.com/stan-dev/cmdstanpy/pull/677 * Allow multiple dicts in inits, fix multichain. https://g | Low | 10/3/2023 |
| v1.1.0 | ### New Functionality - Add method `log_prob` to model class (#637) - Extend `generate_quantities` to non-HMC classes (#634) ### Other changes - Improve type hints (#631) - Serialize draws when pickled (#632) - Raise an error if `src_info` fails (#638) - Change tests to `pytest` format (#639) | Low | 1/25/2023 |
| v1.1.0rc1 | _Note_: This is a release candidate. If no issues are reported, the same version will be published as a full release in one week. ### New Functionality - Add method `log_prob` to model class (#637) - Extend `generate_quantities` to non-HMC classes (#634) ### Other changes - Improve type hints (#631) - Serialize draws when pickled (#632) - Raise an error if `src_info` fails (#638) - Change tests to `pytest` format (#639) | Low | 1/18/2023 |
| v1.0.8 | ## CmdStanPy 1.0.8 - `install_cmdstan` now downloads the correct CmdStan for non-x86 Linux machines (#616). - Improved reporting of errors during `compile()` (#620). - Fixed some edge cases in mixing arguments of the `optimize()` function (#619). - Fixed how `NaN` and infinite numbers were serialized to JSON (#623). - Removed dependency on `ujson`. For now, all JSON serialization is done with the Python standard library. - Added a `timeout` parameter to all model methods which can be use | Low | 10/25/2022 |
| v1.0.7 | ## CmdStanPy 1.0.7 - Fixed a critical bug in how outputs containing complex numbers were read in by CmdStanPy. If you are using models which output complex numbers, please update immediately to ensure you are getting the correct results. | Low | 8/25/2022 |
| v1.0.6 | ## CmdStanPy 1.0.6 - Fixed a build error in the documentation - Improved messages when model fails to compile due to C++ errors. | Low | 8/23/2022 |
| v1.0.5 | ## CmdStanPy 1.0.5 - Fixed a typo in `cmdstanpy.show_versions()` - Reorganized and updated the documentation - Reorganized a lot of internal code - Cleaned up the output of `CmdStanMCMC.draws_pd` - Cleaned up the output of `CmdStanMCMC.summary` - Removed the logging which occurred when Python exited with cmdstanpy imported. | Low | 8/22/2022 |
| v1.0.4 | ## CmdStanPy 1.0.4 - Fix an issue with the `cmdstanpy.install_cmdstan()` function where the installation would report that it had failed even when it had not. | Low | 6/30/2022 |
| v1.0.3 | ## CmdStanPy 1.0.3 - Fix an issue where Stan fit objects were not `pickle`-able when they previously were. Note: We still do not recommend pickling cmdstanpy objects, but rather using functions `save_csvfiles` and `from_csv`. | Low | 6/29/2022 |
| v1.0.2 | ## CmdStanPy 1.0.2 - CmdStanPy can now format (and canonicalize) your Stan files with `CmdStanModel.format()` - Stan variables can now be accessed from fit objects using the `.` syntax when no naming conflicts occur. For example, previous code `fit.stan_variable("my_cool_variable")` can now be written `fit.my_cool_variable` - CmdStanPy is more robust to running in threaded environments and tries harder to not overwrite its own output files - The `install_cmdstan` script can now be run in int | Low | 6/28/2022 |
| v1.0.1 | ## CmdStanPy 1.0.1 - Support new optimizations in CmdStan 2.29 - Support complex numbers as both inputs and outputs of Stan programs - Sped up assembling output by only reading draws at most once - Fixed an issue where a command failing could change your working directory - Improve error messages in some cases - CmdStanPy no longer changes the global root logging level Note: The minimum supported version for CmdStanPy is now Python 3.7. | Low | 2/14/2022 |
| v1.0.0 | After almost 2 years in the beta barrel, weβre proud to release CmdStanPy 1.0. Many thanks to all of our [contributors](https://github.com/stan-dev/cmdstanpy/graphs/contributors), as well as to all users whoβve submitted feature requests and bug reports! CmdStanPy provides access to the Stan compiler, inference algorithms, and diagnostics. It supports both [develop](https://github.com/stan-dev/cmdstan)ment and production workflows and is well-suited for teaching and learning Stan. Why use | Low | 2/14/2022 |
