pystan
Python interface to Stan, a package for Bayesian inference
What it is and what it does
PyStan is a Python interface to Stan, a platform for Bayesian statistical modeling and computation. It lets you define probabilistic models in Stan's modeling language, then compile and sample from them in Python. The package handles model compilation caching and sample caching automatically, reducing redundant computation.
Typical workflows involve writing a Stan model specification that defines data, parameters, and model structure, passing it to PyStan with your data, and drawing posterior samples via Markov chain Monte Carlo. Results can be extracted as arrays or converted to pandas DataFrames for analysis. It's used in social sciences, biology, physics, engineering, and business for statistical inference where you need to quantify uncertainty in model parameters.
Use it for:
- Fit hierarchical Bayesian models to experimental or observational data with uncertainty quantification
- Conduct prior sensitivity analysis and posterior predictive checks for model validation
- Estimate treatment effects, causal parameters, or latent variables in complex statistical models
- Build time-series or spatial models with structured priors and dependencies
- Perform model comparison and selection using posterior samples
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
PyStan provides a Python interface to Stan for Bayesian statistical inference, with automatic caching of compiled models and posterior samples.
Yes, if you need Bayesian inference. PyStan is actively maintained, has no known vulnerabilities, and is widely trusted in research and industry. The main requirement is a C++ compiler on your system. Worth installing for any project involving probabilistic modeling, uncertainty quantification, or hierarchical statistical inference.
Install
pystan on PyPI
pip
pip install pystanuv
uv add pystanpoetry
poetry add pystanInstalling pystan
Before you install
Low friction installation as a pure Python wheel. Actively maintained with recent commits and supports current Python versions (3.12+). Requires a C++ compiler (gcc ≥9.0 or clang ≥10.0) available on your system for model compilation.
License in practice
Licensed under ISC, a permissive open-source license. You can use, modify, and distribute PyStan with minimal restrictions, suitable for both academic and commercial projects.
Quickstart
pip install pystan
import pystan
schools_code = """data { int<lower=0> J; }"""
schools_data = {"J": 8}
posterior = pystan.build(schools_code, data=schools_data)
fit = posterior.sample(num_chains=4, num_samples=1000)
Requires a C++ compiler (gcc ≥9.0 or clang ≥10.0) installed; runs on Linux and macOS only.
Verify before relying
- Whether Windows support is available or planned
- Performance characteristics for large models or datasets
- Specific use of GPU acceleration or distributed computing
Package facts
| License | ISC (permissive) |
| Python support | supports the current Python release (<4.0,>=3.12) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 6 — aiohttp, httpstan, pysimdjson, numpy, clikit, setuptools |
| Maintenance | actively maintained — 155 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 1,440,233/month — #3,892 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: pystan-3.10.1-py3-none-any.whl
Tags
More Mathematics packages
NetworkX provides data structures and…
permissive · top 1,000 on PyPI
kiwisolverkiwisolver is a Python binding to a fast C++…
permissive · top 1,000 on PyPI
sympySymPy is a Python library for symbolic…
permissive · top 1,000 on PyPI
contourpyContourPy calculates contours of 2D…
permissive · top 1,000 on PyPI
torchPyTorch provides GPU-accelerated tensor…
permissive · top 1,000 on PyPI
onnxruntimeonnxruntime loads and executes Open Neural…
permissive · top 1,000 on PyPI
cmdstanpyCmdStanPy provides a pure-Python interface to…
permissive · top 5,000 on PyPI
httpstanhttpstan provides an HTTP REST interface to the…
permissive · top 5,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
pymc3PyMC3 is a Python package for Bayesian…
permissive · top 15,000 on PyPI
arviz-statsProvides statistical computations and…
permissive · top 15,000 on PyPI
arvizArviZ is a Python package for exploratory…
permissive · top 5,000 on PyPI
arviz-baseProvides converters and base data manipulation…
permissive · top 15,000 on PyPI
arviz-plotsarviz-plots provides visualization functions…
permissive · top 15,000 on PyPI