skillfed

emcee

The Python ensemble sampling toolkit for MCMC

emcee v3.1.6 846.6K downloads/30d#4,916 on PyPI1,597
Permissive license MIT Active released

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 emcee

uv

uv add emcee

poetry

poetry add emcee

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersIntended Audience :: Science/ResearchLicense :: OSI Approved :: MIT LicenseOperating System :: OS IndependentProgramming Language :: Python

Tags

MCMC sampling PythonBayesian inference ensembleaffine-invariant samplerposterior estimationGoodman Weare algorithmparallel MCMCparameter fitting Bayesian
bayesian-inferencestatistical-samplingmcmc

More Mathematics packages