fastcausal
Fast, easy-to-use causal discovery analysis tools for Python.
Overview
fastcausal provides a unified Python interface for causal discovery analysis, combining the functionality of several earlier packages into one pip-installable tool. It supports both interactive Jupyter notebook workflows and config-driven batch processing of large datasets.
Key features:
- No Java dependency — uses tetrad-port (C++ port of Tetrad algorithms) instead of Java
- Seven causal discovery algorithms — PC, FGES, GFCI, BOSS, BOSS-FCI, GRaSP, GRaSP-FCI
- Prior knowledge support — temporal tiers, forbidden/required edges
- Bootstrapped stability analysis — edge frequency selection across subsampled runs
- SEM fitting — automatic structural equation modeling via semopy
- Flexible graph visualization — node styling with fnmatch patterns, multi-graph comparison with shared layouts
- Batch pipeline — config-driven processing of hundreds of cases via CLI (in alpha)
- Report generation — automated Word document reports with embedded graphs (in alpha)
Installation
All features — SEM fitting, Jupyter/matplotlib/seaborn, and Word report generation — are included by default.
Conda install (Miniforge3 recommended)
For reproducible environments (especially for graph tooling and notebooks), use the repository's environment.yml with Miniforge3.
-
Install Miniforge3 (conda-forge based):
Download and run the installer for your platform (Windows/Linux/MacOSX) from: https://github.com/conda-forge/miniforge/releases/latest
On Windows machines where you don't have Administrator privileges, on the miniforge install, select "Just Me"
-
Open a new terminal/powershell so
condais available, then create and activate the environment:conda env create -f environment.yml conda activate fastcausal_env
The environment file already installs
fastcausalvia pip and the Graphviz binaries required to create/render graphs.If you are developing from this repository, replace the PyPI install with an editable install:
pip uninstall -y fastcausal pip install -e .
-
Optional sanity check:
python -c "import fastcausal; print(fastcausal.__version__)"
Quick Start
Five lines to your first causal graph:
from fastcausal import FastCausal
fc = FastCausal()
df = fc.load_sample("boston") # bundled EMA dataset
df = fc.standardize(df)
results, graph = fc.run_search(df, algorithm="gfci", alpha=0.01, penalty_discount=1.0)
fc.show_graph(graph)
Time-series workflow with prior knowledge
For time-series data, add lagged columns, standardize, and encode temporal ordering so that yesterday's values can only be causes (not effects) of today's:
from fastcausal import FastCausal
fc = FastCausal()
df = fc.load_sample("boston")
# Add lagged columns and standardize
lag_stub = "_lag"
df_lag = fc.add_lag_columns(df, lag_stub=lag_stub)
df_std = fc.standardize(df_lag)
# Build temporal prior knowledge explicitly:
# Tier 0 (lag vars) can only be parents of Tier 1 (current-day vars)
cols = df.columns
knowledge = {
"addtemporal": {
0: [col + lag_stub for col in cols],
1: [col for col in cols],
}
}
# knowledge =>
# {"addtemporal": {
# 0: ["alcohol_bev_lag", "TIB_lag", "TST_lag", "PANAS_PA_lag",
# "PANAS_NA_lag", "worry_scale_lag", "PHQ9_lag"],
# 1: ["alcohol_bev", "TIB", "TST", "PANAS_PA",
# "PANAS_NA", "worry_scale", "PHQ9"]
# }}
# Run GFCI causal discovery with SEM fitting
result, graph = fc.run_search(
df_std,
algorithm="gfci",
alpha=0.01,
penalty_discount=1.0,
knowledge=knowledge,
)
# Visualize with custom node styles
node_styles = [
{"pattern": "*_lag", "style": "dotted"},
{"pattern": "PANAS_PA*", "style": "filled", "fillcolor": "lightgreen"},
{"pattern": "PANAS_NA*", "style": "filled", "fillcolor": "lightpink"},
{"pattern": "alcohol_bev*", "shape": "box", "style": "filled",
"fillcolor": "purple", "fontcolor": "white"},
]
fc.show_graph(graph, node_styles=node_styles)
See fastcausal_demo_short.ipynb for the full interactive demo.
CLI Usage
fastcausal provides a command-line interface for batch processing:
# Data preparation
fastcausal parse --config proj/config.yaml
# Batch causal discovery across cases
fastcausal run --config proj/config.yaml
fastcausal run --config proj/config.yaml --start 0 --end 50
fastcausal run --config proj/config.yaml --list
# Effect size analysis and heatmaps
fastcausal paths --config proj/config.yaml
# Generate Word report
fastcausal report --config proj/config.yaml --mode 2wide
# Quick single-file analysis
fastcausal analyze data.csv --algorithm gfci --output results/
Supported Algorithms
| Algorithm | Type | Output | Key Parameters |
|---|---|---|---|
| PC | Constraint-based (Fisher Z) | CPDAG | alpha |
| FGES | Score-based (BIC) | CPDAG | penalty_discount |
| GFCI | Hybrid (FGES + FCI rules) | PAG | alpha, penalty_discount |
| BOSS | Permutation-based (BIC) | CPDAG | penalty_discount |
| BOSS-FCI | BOSS + FCI rules | PAG | alpha, penalty_discount |
| GRaSP | Permutation-based (tuck DFS) | CPDAG | penalty_discount |
| GRaSP-FCI | GRaSP + FCI rules | PAG | alpha, penalty_discount |
See the Algorithm Guide for detailed parameter reference, edge types, and selection guidance.
Architecture
fastcausal consolidates four earlier codebases into a layered architecture:
pip install fastcausal
|
fastcausal (API + CLI + viz + SEM + batch)
/ \
tetrad-port dgraph_flex
(C++ algorithms) (graph rendering)
- tetrad-port — C++ port of CMU Tetrad algorithms, exposed via nanobind
- dgraph_flex — Graphviz-based directed graph rendering
Project Structure
fastcausal/
├── core.py # FastCausal class (main API)
├── search.py # Algorithm wrapper (PC, FGES, GFCI, BOSS, GRaSP, ...)
├── sem.py # SEM fitting via semopy
├── transform.py # Lag columns, standardization, subsampling
├── knowledge.py # Prior knowledge handling
├── edges.py # Edge parsing, selection, deduplication
├── cli.py # Click-based CLI
├── viz/
│ ├── styling.py # fnmatch-based node styling
│ ├── graphs.py # Graph display and save (single + multi)
│ └── plots.py # Heatmaps and effect size plots
├── pipeline/
│ ├── config.py # YAML config parsing (v4.0 + v5.0)
│ ├── parse.py # Data preparation engine
│ ├── batch.py # Batch causal discovery
│ ├── paths.py # Effect size analysis
│ ├── report.py # Word document generation
│ └── metrics.py # Graph metrics (centrality, ancestors)
└── io/
├── data.py # CSV loading, sample datasets
└── wearables.py # Fitbit/Garmin integration (planned)
Documentation
- Algorithm Guide — Algorithm selection, parameters, edge types, prior knowledge
- Migration from fastcda — API mapping for fastcda users
- Migration from cda_tools2 — CLI mapping for cda_tools2 users
- Consolidation Plan — Implementation plan and phase status
- Project Conventions — Development guidelines and conventions
Config File Format
fastcausal uses YAML config files for batch processing. Version 5.0 is the current format; version 4.0 (from cda_tools2) is accepted with a deprecation warning.
GLOBAL:
version: 5.0
name: my_project
title: "My Causal Analysis"
CAUSAL:
algorithm: gfci
alpha: 0.05
penalty_discount: 1.0
knowledge: prior.txt
standardize_cols: true
Requirements
- Python >= 3.11
- tetrad-port >= 0.1.0
- dgraph_flex >= 0.1.11
- Graphviz (system install for graph rendering)
License
MIT
Citation
If you use fastcausal in your research, please cite the relevant algorithm papers and this package.
The bundled "boston" EMA dataset is from:
Cunningham TJ, Fields EC, Kensinger EA. "Boston College daily sleep and well-being survey data during early phase of the COVID-19 pandemic." Sci Data. 2021. https://www.nature.com/articles/s41597-021-00886-y
Metadata
Release files for fastcausal 0.1.11
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| fastcausal-0.1.11.tar.gz | 53.6 kB | Without provenance | Details for fastcausal-0.1.11.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fastcausal-0.1.11-py3-none-any.whl | Python 3 | none | any | Details for fastcausal-0.1.11-py3-none-any.whl |
Total release size: 102.1 kB
Release files / fastcausal-0.1.11.tar.gz
| Download URL | fastcausal-0.1.11.tar.gz |
|---|---|
| Size | 53.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
243aa0a86729f680f823810cde356516bb5beed3d47cc553f862a8b6e76adb18
|
|
BLAKE2b-256 checksum How to use checksums |
4446c59a043ed5f452d6ec6e2a76e840c52c90bd42389603b01a864010e60a7b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Release files / fastcausal-0.1.11-py3-none-any.whl
| Download URL | fastcausal-0.1.11-py3-none-any.whl |
|---|---|
| Size | 48.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
28b68fd79eb43b0f8fd290d71190577624a2e344d9268dfa5836b032a9cd9335
|
|
BLAKE2b-256 checksum How to use checksums |
80a4a01abd3ae48404b7286ac0011bd3c9a59d2ab36b0ffa9f133073cec4780f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.3
|
Security for fastcausal 0.1.11
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.