Skip to main content

Python interface to CmdStan

Project description


CmdStanPy is a lightweight interface to Stan for Python users which provides the necessary objects and functions to compile a Stan program and run Stan's samplers.


  • Clean interface to Stan services so that CmdStanPy can keep up with Stan releases.

  • Provides complete control - all sampler arguments have corresponding named argument for CmdStanPy sampler function.

  • 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 sample from the posterior, downstream modules do the analysis.



Source Repository

CmdStan's source-code repository is hosted here on GitHub.


The CmdStanPy, CmdStan, and the core Stan C++ code are licensed under new BSD.



import os
from cmdstanpy import Model, StanFit, cmdstan_path

# specify Stan file, create, compile Model object
bernoulli_path = os.path.join(cmdstan_path(), 'examples', 'bernoulli', 'bernoulli.stan')
bernoulli_model = Model(stan_file=bernoulli_path)

# specify data, fit the model
bernoulli_data = { "N" : 10, "y" : [0,1,0,0,0,0,0,0,0,1] }
bernoulli_fit = bernoulli_model.sample(chains=5, cores=3, data=bernoulli_data)

# summarize the results (wraps CmdStan `bin/stansummary`):

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for cmdstanpy, version 0.5.0
Filename, size File type Python version Upload date Hashes
Filename, size cmdstanpy-0.5.0-py3-none-any.whl (33.1 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size cmdstanpy-0.5.0.tar.gz (38.0 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page