Open-source project
PacktPublishing/Causal-Inference-and-Discovery-in-Python avatar
PacktPublishing/Causal-Inference-and-Discovery-in-Python

This causal inference repository is a book with fifteen notebooks, and the environment files are the real documentation

Causal Inference and Discovery in Python by Packt Publishing

1,050 stars365 forksJupyter NotebookMIT

At a glance

What is it?
The code companion to a Packt title on causal machine learning, with one Jupyter notebook per chapter, seven causal libraries pinned in a software list, and three environment files for different hardware. It is a teaching artefact rather than a library, and reading it as a reference project means reading the pinning decisions.
Who is it for?
Adopt this repository if you are learning causal machine learning and want working notebooks for the standard libraries rather than five minutes of setup. Do not adopt it as a production dependency, because it is a book with an erratum and three competing environment files rather than a maintained package.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Yes. The repository last received commits 116 days ago.
What is it written in?
Mainly Jupyter Notebook, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on November 7, 2026, and from our analysis. They are not legal advice.

From daily snapshots

Star history

  • PacktPublishing/Causal-Inference-and-Discovery-in-Python1,050 ★ · +6
Star history
Repository2026-10-212026-11-07
PacktPublishing/Causal-Inference-and-Discovery-in-Python1k1.1k

6 Stars in the last 17 days, measured from the daily GitHub snapshot. Compare with other projects

Editorial analysis

One notebook per chapter, and the naming tells you the structure

The repository is the code for the book Causal Inference and Discovery in Python, published by Packt, and the primary language is recorded as Jupyter Notebook, which is a good summary of the whole thing.

The top level is a flat list of notebooks. Chapter_01 through Chapter_10, then Chapter_11.1 and Chapter_11.2, then Chapter_13 and Chapter_14. There is no Chapter_12 file, and there is no Chapter_15 either, although the software list says the code covers chapters 1 to 15. The extras are named differently, with EXP standing for experiment for Chapter_09, plus Extras_01__DGPs and Extras_02__Additional_computations, which suggests a background process or a different generative model in the abbreviation.

Alongside the notebooks there is a `data/` directory, a `models/` directory, an `img/` directory for images, a `docs/` directory and an `errata/` directory. That last one is a nice touch for a book repository, and the README carries a matching errata entry, so corrections are tracked in two places.

The README also includes a short example of what the code looks like.

python
preds = causal_bert.inference(
    texts=df['text'],
    confounds=df['has_photo'],
)[0]

That snippet is worth a moment because it shows the shape of the causal estimation API being used. A model called `causal_bert` takes texts and a confounds column and returns predictions, with the first element extracted from the result. The confound is `has_photo`, which is a nice illustration of the kind of variable the book is about, since presence of a photo in a post is plausibly associated with engagement and plausibly associated with the text, which is exactly the confounding structure the 4 step process is designed to handle.

The last push to the repository was on 2026-07-15 and the repository is not archived, with no GitHub releases, so the artefact is the repository itself rather than a versioned package.

Seven causal libraries pinned to versions from one year

The software and hardware list is the most useful section in the README for anyone who wants to run the code, and it is a table where every chapter from 1 to 15 requires the same stack.

Python 3.9 is the required version, and then seven libraries: DoWhy 0.8, EconML 0.12.0, CATENets 0.2.3, gCastle 1.0.3, Causica 0.2.0, Causal-learn 0.1.3.3 and Transformers 4.24.0. All of them run on Windows, macOS or Linux.

The list is a map of the field rather than a dependency list. DoWhy is the modelling framework that the 4 step process is built around, and EconML is the estimation library that does the heavy lifting on heterogeneous treatment effects and uplift. CATENets and gCastle are causal discovery libraries, with gCastle being the graph learning one and CATENets the counterfactual one, and Causal-learn is another discovery toolkit. Causica is a package for automatically learning causal models from data, and Transformers 4.24.0 is there for the text based causal BERT example in the snippets above.

So the book covers both halves of the field, effect estimation and structure discovery, with several libraries for each, and pinning the versions lets a reader run the same code the author ran.

The versions are the part to look at critically. DoWhy 0.8 and EconML 0.12.0 with Transformers 4.24.0 and Python 3.9 place this stack in the 2023 era, and the Python 3.9 requirement is now two versions behind. That is the normal consequence of a book repository, which is frozen at publication, and it is also the reason the environment files matter.

Three environment files, and the hardware difference is the reason

The repository carries three environment definitions, and the file names are the explanation.

There is `causal-pymc.yml`, which is a conda environment file. There is `causal_book_py39_cuda117.yml`, which is a conda environment pinned to CUDA 11.7. And there is a plain text file named `causal_book_py39_apple_m1_(experimental-by-ferrari-leo).txt`, which is the Apple Silicon environment, and whose name says both that it is experimental and who put it together.

The naming tells you the priority. The CUDA file is the main path for anyone with an NVIDIA GPU, the PyMC file covers the probabilistic programming stack, and the Apple Silicon one is explicitly marked as experimental, contributed rather than maintained by the author.

The existence of a CUDA environment is a signal about the content rather than about the tooling. A causal discovery library is the kind of thing where a GPU is worth having, because estimating hundreds of candidate structures or running a large ensemble of interventions is a workload that benefits from parallel hardware, and the presence of a dedicated CUDA 11.7 environment means the author expected readers to run the heavy chapters on a GPU.

The Apple Silicon note is worth reading in a wider context. A book repository frozen in 2023 with an experimental Apple Silicon environment is a snapshot of a moving target, and the practical consequence is that the environment file tells you what worked, not what will install cleanly today.

What the book covers, and what the repository shows

The README describes a three part progression, and the notebook structure follows it.

The first part is motivations behind causal thinking and a thorough introduction to Pearlian causal concepts, including structural causal models, interventions and counterfactuals. The description says each concept comes with a theoretical explanation and a set of practical exercises with Python code, which is why there is a notebook per chapter rather than a library.

The second part is causal effect estimation, moving progressively towards modern machine learning methods, and the description mentions exploring the mechanics of how causes leave traces and comparing the main families of causal discovery algorithms. The discovery libraries in the dependency list, CATENets, gCastle, Causal-learn and Causica, map onto that comparison.

The final part looks at the future of causal AI, with challenges and opportunities and a list of resources to learn more.

The feature list the README gives is a summary of the learning objectives. Mastering the fundamental concepts of causal inference, the mysteries of structural causal models, the 4 step causal inference process in Python, advanced uplift modeling techniques, modern causal discovery in Python, and causal inference for social impact and community benefit.

Uplift modeling is the one term worth flagging for engineers. It is the estimation of the incremental effect of an action on a particular individual rather than the average effect on a population, which is what a marketing team or a treatment assignment system actually needs, and EconML is the library that does it. If your work is targeted rather than population level, the estimation chapters are the ones to read rather than the discovery ones.

The audience the README names is machine learning engineers, data scientists and machine learning researchers who want to extend their toolkit, plus developers familiar with causality in another technology who want to switch to Python, and data scientists with a background in traditional causality who want to learn causal machine learning.

An erratum, a Discord and the marketing around a book repository

Two things in the repository are worth reading with care.

The first is the errata. The README records one correction: on page 33, the formula Y := TU + (T minus 1)(U minus 1) should be Y := T times U. That is a genuine error in a printed formula, and it is exactly the kind of thing that is impossible to see in a notebook and easy to get wrong in a book, since a notebook reader would derive the correct behaviour from the code while a book reader copies the formula. The `errata/` directory in the repository presumably holds the fuller list, and the practice of publishing errata at all is a good sign about the production process.

The second is the packaging. A large part of the README is newsletter promotion, with a DataPro newsletter for data scientists and a BIPro newsletter for BI professionals, both with subscriber counts, plus a Discord community invitation. The main body of the document, the part describing the book and the code, is maybe a third of the file.

That is worth naming because it tells you what this repository is. It is a marketing and distribution artefact for a book, with the notebooks as the payload. A Packt code repository is not the same thing as an open source library with a maintainer, a roadmap and a changelog. There is no CHANGELOG in the top level entries, no issue tracker discussion about the code, and the licence is MIT, which applies to the notebook code.

So the right way to consume it is as a worked reference. The exercises give you the right sequence of steps for each concept, the environment files give you a working dependency set, and the errata tells you where the printed text and the code disagree. What it will not give you is a maintained package, and anyone planning to build on the code should extract the parts they need into their own repository with their own pins.

The author section and the related products section are the remaining parts of the README, and they confirm the shape: this is a book, sold and supported as one, with the repository as a companion.

Editorial conclusion

Adopt this repository if you are learning causal machine learning and want working notebooks for the standard libraries rather than five minutes of setup. Do not adopt it as a production dependency, because it is a book with an erratum and three competing environment files rather than a maintained package. Verify first that the pinned library versions still install on your Python, since the list targets Python 3.9 and versions from 2023, and that the environment file matching your hardware is the one you use, because the CUDA and Apple Silicon files are marked differently for good reason.

Frequently asked questions

What is the Causal Inference and Discovery in Python repository?

It is the code repository for the Packt book of the same name, with one Jupyter notebook per chapter, extras notebooks, a data directory, a models directory, an errata directory and three environment files. The primary language is Jupyter Notebook and the licence is MIT.

Which libraries do the book notebooks require?

The software list gives Python 3.9 with DoWhy 0.8, EconML 0.12.0, CATENets 0.2.3, gCastle 1.0.3, Causica 0.2.0, Causal-learn 0.1.3.3 and Transformers 4.24.0, all for chapters 1 to 15 on Windows, macOS or Linux.

Why are there three environment files in the repository?

One is a conda environment for PyMC, one is pinned to CUDA 11.7 for NVIDIA GPUs, and the third is a plain text file for Apple Silicon, which is marked experimental and attributed to an outside contributor.

Is there an erratum for the book?

Yes. The README records that on page 33 the formula Y := TU + (T minus 1)(U minus 1) should be Y := T times U, and the repository has an errata directory for corrections.

What topics does the book cover?

Pearlian causal concepts such as structural causal models, interventions and counterfactuals, then causal effect estimation moving towards modern machine learning methods, comparison of the main families of causal discovery algorithms, uplift modeling, and a final outlook on causal AI.

Official sources

  1. Issues
  2. License: MIT
  3. PacktPublishing/Causal-Inference-and-Discovery-in-Python on GitHub
  4. README
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/packtpublishing-causal-inference-and-discovery-in-python.svg)](https://hysenlabs.com/projects/packtpublishing-causal-inference-and-discovery-in-python)

Star history chart for your README

markdown
[![Star history](https://hysenlabs.com/chart/packtpublishing-causal-inference-and-discovery-in-python.svg)](https://hysenlabs.com/projects/packtpublishing-causal-inference-and-discovery-in-python)

Was this useful?