Skip to main content

PyPI version conda-forge License

Build Status Ruff pre-commit codecov

GitHub Repo stars Read the Docs Downloads PyPI - Downloads

Causal Inference for Quasi-Experiments

Research-grade causal inference workflows for quasi-experimental designs in Python.

CausalPy helps you estimate causal effects with transparent assumptions, uncertainty-aware modeling, and reproducible outputs:

  • Quasi-experimental methods: Difference-in-differences, synthetic control, regression discontinuity, interrupted time series, instrumental variables, and more
  • Bayesian-first estimation via PyMC with full uncertainty quantification, plus traditional OLS via scikit-learn
  • Decision-ready outputs: Effect summaries with credible intervals (HDI), practical significance (ROPE), and publication-quality plots

📞 Book a consulting call

CausalPy is built and maintained by PyMC Labs. If your team is exploring a consulting engagement for lift testing, complex or high-stakes causal work, you can book an introductory call. These calls are for consulting inquiries only. For technical usage questions and free community support, please use GitHub Discussions and the documentation below.

Help and documentation

Installation

To get the latest release:

pip install CausalPy

or via conda:

conda install causalpy -c conda-forge

Alternatively, if you want the very latest version of the package you can install from GitHub:

pip install git+https://github.com/pymc-labs/CausalPy.git

AI Agent Skills

CausalPy includes agent skills that teach AI coding assistants how to use the library for causal inference. Skills are available via Decision AI Hub and live in causalpy/skills/ in the source tree.

Quickstart

import causalpy as cp
import matplotlib.pyplot as plt

# Import and process data
df = (
    cp.load_data("drinking")
    .rename(columns={"agecell": "age"})
    .assign(treated=lambda df_: df_.age > 21)
)

# Run the analysis
result = cp.RegressionDiscontinuity(
    df,
    formula="all ~ 1 + age + treated",
    running_variable_name="age",
    model=cp.pymc_models.LinearRegression(),
    treatment_threshold=21,
)

# Visualize the causal effect at the threshold
fig, ax = result.plot()

# Get a results summary with posterior estimates
result.summary()

The result.plot() visualizes the regression discontinuity design, showing the estimated jump at the treatment threshold. The result.summary() prints posterior estimates of the causal effect with uncertainty intervals.

Videos

Click on the thumbnail below to watch a video about CausalPy on YouTube.

Youtube video thumbnail image

When CausalPy is a good fit

  • You have a plausible quasi-experimental design (threshold rule, policy change, staggered rollout, geo lift, etc.)
  • You want uncertainty-aware estimates and diagnostics, not only point estimates
  • You need reproducible analysis artifacts for review and communication

When CausalPy is not a fit

  • You need causal discovery from weakly identified observational data
  • You want fully automated "black box" causal answers without specifying assumptions
  • You primarily need production workflow tooling (pipelines, governance, multi-user collaboration)

Methods and Workflows

CausalPy provides methods for common causal inference decision contexts:

Decision context Methods
Focussed testing on certain units (geos, products) Synthetic control, Geographical lift
Evaluate before/after changes, launches, policy changes Differences in Differences, Staggered DiD, Interrupted time series
Exploit cutoff rules, score-based eligibility (credit, age) Regression discontinuity, Regression kink
Can't randomize, correct for selection Instrumental variables, Inverse propensity weighting
Group differences, control for covariates ANCOVA

Available methods

Method Description
Synthetic control Constructs a synthetic version of the treatment group from a weighted combination of control units. Used for causal inference in comparative case studies when a single unit is treated, and there are multiple control units.
Geographical lift Measures the impact of an intervention in a specific geographic area by comparing it to similar areas without the intervention. Commonly used in marketing to assess regional campaigns.
ANCOVA Analysis of Covariance combines ANOVA and regression to control for the effects of one or more quantitative covariates. Used when comparing group means while controlling for other variables.
Differences in Differences Compares the changes in outcomes over time between a treatment group and a control group. Used in observational studies to estimate causal effects by accounting for time trends.
Staggered Difference-in-Differences Estimates event-time treatment effects when different units adopt treatment at different times, using an imputation approach that models untreated outcomes and compares observed outcomes to counterfactual predictions.
Regression discontinuity Identifies causal effects by exploiting a cutoff or threshold in an assignment variable. Used when treatment is assigned based on a threshold value of an observed variable, allowing comparison just above and below the cutoff.
Regression kink designs Focuses on changes in the slope (kinks) of the relationship between variables rather than jumps at cutoff points. Used to identify causal effects when treatment intensity changes at a threshold.
Interrupted time series Analyzes the effect of an intervention by comparing time series data before and after the intervention. Used when data is collected over time and an intervention occurs at a known point, allowing assessment of changes in level or trend.
Instrumental variable regression Addresses endogeneity by using an instrument variable that is correlated with the endogenous explanatory variable but uncorrelated with the error term. Used when explanatory variables are correlated with the error term, providing consistent estimates of causal effects.
Inverse Propensity Score Weighting Weights observations by the inverse of the probability of receiving the treatment. Used in causal inference to create a synthetic sample where the treatment assignment is independent of measured covariates, helping to adjust for confounding variables in observational studies.

Diagnostics-first by design

CausalPy emphasizes transparent, uncertainty-aware outputs for rigorous causal analysis:

  • Effect summaries: Every experiment provides effect_summary() returning decision-ready statistics with both tabular and prose formats
  • Uncertainty quantification: Bayesian models report HDI (Highest Density Intervals); OLS models report confidence intervals
  • Practical significance: ROPE (Region of Practical Equivalence) analysis to assess whether effects exceed meaningful thresholds
  • Direction testing: Tail probabilities (e.g., P(effect > 0)) for directional inference

Citing CausalPy

If you use CausalPy in your research, please cite it. A Zenodo DOI for stable releases is planned. In the meantime, you can cite the repository:

@software{causalpy,
  author = {{PyMC Labs}},
  title = {CausalPy: Causal inference for quasi-experiments in Python},
  url = {https://github.com/pymc-labs/CausalPy},
  year = {2026}
}

Roadmap

Plans for the repository can be seen in the Issues.

License

Apache License 2.0

Thanks to our contributors

CausalPy contributors

The contributor image is regenerated weekly by a GitHub Actions workflow (.github/workflows/contributors.yml) that opens a PR when the contributor list changes.

Download files

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

Source Distribution

causalpy-0.9.0.tar.gz (1.3 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

causalpy-0.9.0-py3-none-any.whl (1.4 MB view details)

Uploaded Python 3

File details

Details for the file causalpy-0.9.0.tar.gz.

File metadata

  • Download URL: causalpy-0.9.0.tar.gz
  • Upload date:
  • Size: 1.3 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for causalpy-0.9.0.tar.gz
Algorithm Hash digest
SHA256 836a79a877b1fef6914df81d311dc576b805f0f38882d5affb3c45c1473821d4
MD5 fc30775f2e96f25689734fad30800d18
BLAKE2b-256 8b52492f4a94e28534ed0d7815ce6fd31ffeccd397f6818f18c66e4bc1f67e1b

See more details on using hashes here.

Provenance

The following attestation bundles were made for causalpy-0.9.0.tar.gz:

Publisher: release.yml on pymc-labs/CausalPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file causalpy-0.9.0-py3-none-any.whl.

File metadata

  • Download URL: causalpy-0.9.0-py3-none-any.whl
  • Upload date:
  • Size: 1.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.14

File hashes

Hashes for causalpy-0.9.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fe3f4505a61426d17f54c44c8798c9f731c4d173b1cae26739441ace5a95346
MD5 dcc8e0dad89ffd4170af6e97eb351248
BLAKE2b-256 b8d2e1e8a66cc235d2338f596782927445e5c98269ed48728bcc7da3a741ae27

See more details on using hashes here.

Provenance

The following attestation bundles were made for causalpy-0.9.0-py3-none-any.whl:

Publisher: release.yml on pymc-labs/CausalPy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.9.0 This release

2 files

0.8.1

2 files

0.8.0

2 files

0.7.0

2 files

0.6.0

2 files

0.5.0

2 files

0.4.2

2 files

0.4.1

2 files

0.4.0

2 files

0.3.1

2 files

0.3.0

2 files

0.2.3

2 files

0.2.2

2 files

0.2.1

2 files

0.2.0

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

0.0.14

2 files

0.0.13

2 files

0.0.12

2 files

0.0.10

2 files

0.0.9

1 file

0.0.8

1 file

0.0.7

1 file

0.0.6

1 file

0.0.5

1 file

0.0.4

1 file

0.0.3

1 file

0.0.2

1 file

0.0.1

1 file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page