skillfed

pystan

Python interface to Stan, a package for Bayesian inference

pystan v3.10.1 1.4M downloads/30d#3,892 on PyPI366
Permissive license ISC Active released

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 pystan

uv

uv add pystan

poetry

poetry add pystan

Installing 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

Intended Audience :: Science/ResearchLicense :: OSI ApprovedLicense :: OSI Approved :: ISC License (ISCL)Programming Language :: Python :: 3Programming Language :: Python :: 3.12

Tags

bayesian inference pythonstan statistical modelingprobabilistic programmingmcmc samplinghierarchical bayesian modelsposterior samplingstatistical computation
bayesian-inferencestatistical-modelingprobabilistic-programming

More Mathematics packages