emcee
The Python ensemble sampling toolkit for MCMC
What it is and what it does
emcee is a production-grade Python implementation of the affine-invariant ensemble sampler for MCMC, a statistical technique for sampling from complex probability distributions. It is commonly used in Bayesian inference, parameter estimation, and model fitting where you need to explore a posterior distribution and extract credible intervals or point estimates. The package wraps the algorithm proposed by Goodman & Weare (2010) and has been used in published astrophysics research.
The core dependency is numpy, and the package is designed to run on standard Python without compiled extensions. It provides an ensemble-based approach where multiple parallel walkers explore the parameter space, making it well-suited for problems where traditional single-chain samplers would be slow or inefficient. The API is straightforward: define a log-probability function, initialize an EnsembleSampler, and call run_mcmc to generate samples.
Use it for:
- Fitting model parameters to observational data in astronomy or physics by sampling the posterior distribution.
- Uncertainty quantification in scientific computing where you need credible intervals on fitted parameters.
- Bayesian model comparison by computing marginal likelihoods or evidence from MCMC chains.
- Calibrating complex simulators or forward models by inferring input parameters that match observed outputs.
- Exploratory data analysis in high-dimensional spaces where you need to understand the structure of a probability distribution.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
emcee implements affine-invariant ensemble sampling for Markov chain Monte Carlo (MCMC), enabling Bayesian inference and parameter estimation through parallel sampling of posterior distributions.
Yes. emcee is a mature, well-maintained library with low install friction, no known vulnerabilities, and a permissive license. It is the standard choice for ensemble MCMC in Python and has proven utility in published research. Install it if you need to perform Bayesian inference or sample from complex posterior distributions.
Install
emcee on PyPI
pip
pip install emceeuv
uv add emceepoetry
poetry add emceeInstalling emcee
Before you install
Low install friction with a single runtime dependency (numpy) and a pure-Python wheel distribution. The package is actively maintained with a recent release and 1597 repository stars, indicating stable community adoption.
License in practice
MIT license permits unrestricted commercial and private use, modification, and distribution with minimal restrictions—suitable for most research and production contexts.
Quickstart
import numpy as np
import emcee
# Define log-probability function
def log_prob(x):
return -0.5 * np.sum(x**2)
# Initialize sampler with walkers and dimensions
sampler = emcee.EnsembleSampler(n_walkers, n_dims, log_prob)
# Run MCMC
sampler.run_mcmc(initial_state, n_steps)
Verify before relying
- Whether the package supports GPU acceleration or distributed computing beyond standard multiprocessing.
- Performance characteristics and scalability limits for high-dimensional parameter spaces.
- Compatibility with modern Python versions (requires_python is unspecified in metadata).
- Recommended walker count and step count for typical inference problems.
Package facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — numpy |
| Maintenance | actively maintained — 847 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 846,561/month — #4,916 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: emcee-3.1.6-py2.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
iterative-ensemble-smootherImplements ensemble-based data assimilation and…
copyleft · top 15,000 on PyPI
pymc3PyMC3 is a Python package for Bayesian…
permissive · top 15,000 on PyPI
tensorflow-probabilityTensorFlow Probability provides probabilistic…
permissive · top 5,000 on PyPI
pymcPyMC is a Python package for Bayesian…
permissive · top 5,000 on PyPI
nutpienutpie provides a fast NUTS sampler for…
permissive · top 15,000 on PyPI
pymc-extrasExtends PyMC with specialized distributions,…
permissive · top 15,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
numpyroNumPyro is a probabilistic programming library…
permissive · top 15,000 on PyPI
google-meridianMeridian is a Bayesian marketing mix modeling…
unclear · top 15,000 on PyPI