Skip to main content

A Python toolkit for causal inference and experimentation

Project description

Causalis

PyPI version PyPI Downloads Python License: MIT Code quality Docs

Causalis logo

Robust causal inference for experiments and observational studies in Python, organized around scenarios (e.g., Classic RCT, CUPED, Unconfoundedness) with a consistent fit() → estimate() workflow.

Why Causalis?

Causalis focuses on:

  • Scenario-first workflows (you pick the study design; Causalis provides best-practice defaults).
  • Extensive robustness tests that reveal issues in the study design or model specification
  • Pydantic data contracts
  • An advanced DGP (Data Generating Process) with heterogeneous treatment effects, latent variables, and correlated confounders
  • A website with notebooks based on real-world cases

Installation

Recommended

pip install causalis

Quickstart: Classic RCT (difference in means + inference)

from causalis.dgp import generate_classic_rct_26
from causalis.scenarios.classic_rct import DiffInMeans, check_srm

# Synthetic RCT data as a validated CausalData object
data = generate_classic_rct_26(seed=42, return_causal_data=True)

# Optional: Sample Ratio Mismatch check
srm = check_srm(data, target_allocation={0: 0.5, 1: 0.5}, alpha=1e-3)
print("SRM detected?", srm.is_srm, "p=", srm.p_value, "chi2=", srm.chi2)

# Estimate treatment effect with t-test inference (or bootstrap / conversion_ztest)
result = DiffInMeans().fit(data).estimate(method="ttest", alpha=0.05)
result.summary()

Quickstart: Observational study (Unconfoundedness / DML IRM)

from causalis.scenarios.unconfoundedness.dgp import generate_obs_hte_26
from causalis.scenarios.unconfoundedness import IRM
from causalis.data_contracts import CausalData

causaldata = generate_obs_hte_26(return_causal_data=True, include_oracle=False)

from causalis.scenarios.unconfoundedness import IRM

model = IRM().fit(causaldata)
result = model.estimate(score='ATTE')
result.summary()

Binary sensitivity protocol for observational DML/IRM

Pre-specify a practically meaningful effect boundary and one or more domain-justified groups of observed pre-treatment confounders. The primary decision uses element-based long/short gain statistics for the benchmark group. Its r2_y, r2_d, and rho are calibrated jointly from the outcome variance, Riesz-representer variance, and actual effect shift. The 2× strength and forced rho=1 scenarios are reported as secondary stress tests.

from causalis.scenarios.unconfoundedness.refutation import run_sensitivity_protocol

# Example only: replace with a domain-justified, pre-specified group.
primary_group = list(causaldata.confounders[:2])

protocol = run_sensitivity_protocol(
    model,
    causaldata,
    benchmark_groups={"primary_domain_benchmark": primary_group},
    decision_threshold=0.0,  # replace with the minimum practical effect
    direction="positive",
    preconditions_passed=True,  # causal set, overlap, nuisance quality, stability
)

print(protocol["status"])
print(protocol["summary"])
protocol["primary"]
protocol["stress"]
protocol["adversarial"]

PASS means every primary benchmark's bias-aware confidence interval remains strictly beyond decision_threshold in the requested direction. RV and RVa are reported as robustness diagnostics, not compared with universal cutoffs. An empty benchmark set, failed external preconditions, unavailable sensitivity elements, or strengths outside the finite sensitivity domain produce FAIL.

Benchmark boundary handling matches DoubleML: raw cf_y and cf_d are clipped to [0, 1]. If either long/short gain is not strictly positive, primary and stress use rho=sign(theta_short-theta_long); the adversarial scenario still forces rho=1. protocol["benchmarks"] retains raw gains, clipping/fallback flags, long/short elements, and warnings for auditability. In particular, a negative cf_d_raw becomes a numerical cf_d=0 boundary benchmark rather than a missing scenario.

Pick your scenario

Scenario Estimator Assumptions
Classic RCT Difference in means (ttest, ztest, welch_permutation_t_test) Random assignment, no sample ratio mismatch, SUTVA
CUPED CUPED-adjusted difference in means with Lin specification Random assignment, no sample ratio mismatch, SUTVA, valid pre-period metrics
Unconfoundedness DML IRM Unconfoundedness, Overlap, SUTVA, No leakage, Score stability
GATE DML IRM (GATE and GATET) Same assumptions as unconfoundedness, plus meaningful pre-specified or validated subgroup definitions.
Multi Unconfoundedness Multi DML IRM Unconfoundedness, Multi class Overlap, SUTVA, No leakage, Score stability
Synthetic Control ASCM No interference / spillovers, No anticipation, The treated unit’s untreated outcome path is well approximated by the donor pool
Difference in Difference CallawaySantAnnaDID Parallel trends, no anticipation, stable group composition, no spillovers between treated and control groups.
IV DML IV First-stage strength, Reduced form, Instrument balance by Z, Instrument propensity / predictability
Uplift / CATE scoring DML IRM (CATE) Identified treatment effects from randomized or unconfounded data, overlap, calibrated individual-level predictions.

Introduction to Causal Inference: guide

See scenario notebooks: https://causalis.causalcraft.com/explore-scenarios

Contributing guidelines

Maintainers

Ioann Martynov

References

https://github.com/DoubleML/doubleml-for-py

Search terms / supported methods

Causalis covers methods often searched as:

  • causal inference Python
  • causal machine learning Python
  • treatment effect estimation
  • A/B testing Python
  • randomized controlled trial analysis
  • CUPED Python
  • Double Machine Learning Python
  • DML / IRM
  • CATE estimation
  • uplift modeling
  • propensity score diagnostics
  • synthetic control Python
  • difference-in-differences Python

Project details


Download files

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

Source Distribution

causalis-1.0.6.tar.gz (30.1 MB view details)

Uploaded Source

Built Distribution

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

causalis-1.0.6-py3-none-any.whl (458.7 kB view details)

Uploaded Python 3

File details

Details for the file causalis-1.0.6.tar.gz.

File metadata

  • Download URL: causalis-1.0.6.tar.gz
  • Upload date:
  • Size: 30.1 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for causalis-1.0.6.tar.gz
Algorithm Hash digest
SHA256 f02e3cfec3f0f18d9fa945500f8fc317fe5ec843baf0eab0d1b7bffec8cd9084
MD5 45c6f878b44f5f45b9ea5341f1c97ad9
BLAKE2b-256 40dc48fed48ab6113fa3855a5f2405f5e84536dbe6e53fb2d99a80986ecef8cc

See more details on using hashes here.

Provenance

The following attestation bundles were made for causalis-1.0.6.tar.gz:

Publisher: release.yml on causalis-causalcraft/Causalis

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

File details

Details for the file causalis-1.0.6-py3-none-any.whl.

File metadata

  • Download URL: causalis-1.0.6-py3-none-any.whl
  • Upload date:
  • Size: 458.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for causalis-1.0.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ef4ee38a949d2e929bad76b45af3354c8d4e14c563a541952603591cd224386e
MD5 04c7f62235787b16ad3420afb69ec4b3
BLAKE2b-256 a932f740bd8ea63a18bc328f788812ad1ad2047be6b9583a6304a6d494a8fc6f

See more details on using hashes here.

Provenance

The following attestation bundles were made for causalis-1.0.6-py3-none-any.whl:

Publisher: release.yml on causalis-causalcraft/Causalis

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

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page