# Algebraic effects in Python?

**URL:** <https://discuss.python.org/t/algebraic-effects-in-python/107957>\
**Category:** Python Help\
**Tags:** help\
**Created:** [June 29, 2026, 9:40pm UTC](https://discuss.python.org/t/algebraic-effects-in-python/107957 "2026-06-29T21:40:15Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![tar.cf.xz](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@tar.cf.xz](https://discuss.python.org/u/tar.cf.xz)\
**Post date:** [June 29, 2026, 9:40pm UTC](https://discuss.python.org/t/algebraic-effects-in-python/107957/1 "2026-06-29T21:40:15Z")

</div>

I’m trying to map out what’s already been done with algebraic effects / effect handlers in Python, and I’d love pointers from people who know the space.

I’m aware generators (`yield` / `send`) and context managers can approximate one-shot, shallow handlers, but I’m more interested in fuller or more principled attempts — libraries, research experiments, or write-ups.

A few things I’m specifically curious about:

- libraries that implement effects as a first-class abstraction
- anything that tackles multi-shot continuations (greenlets? CPS transforms?)
- how these compare to handlers in Koka / Eff / OCaml

Pointers, war stories, or “don’t bother, here’s why” all welcome.

---

<div class="post-metadata">

**Author:** ![Dutcho](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/dutcho/32/7074_2.png) [@Dutcho](https://discuss.python.org/u/Dutcho)\
**Post date:** [June 30, 2026, 7:22pm UTC](https://discuss.python.org/t/algebraic-effects-in-python/107957/2 "2026-06-30T19:22:20Z")

</div>

I had to look that up. Thanks for the opportunity to learn.

On PyPI, some matches exist that you may want to explore: [simple-eff](https://pypi.org/project/simple-eff/) and [eff](https://pypi.org/project/eff/). Looking at their release history, the topic seems far from mainstream.

---

<div class="post-metadata">

**Author:** ![a-reich](https://sea2.discourse-cdn.com/flex002/user_avatar/discuss.python.org/a-reich/32/5885_2.png) [@a-reich](https://discuss.python.org/u/a-reich)\
**Post date:** [July 1, 2026, 1:30pm UTC](https://discuss.python.org/t/algebraic-effects-in-python/107957/3 "2026-07-01T13:30:26Z")

</div>

Most likely, some of the concepts you’re looking for are hard to even define (at least in a meaningful way) for Python, because the language is fundamentally so different from ones designed to focus purely on the functional paradigm.

---

<div class="post-metadata">

**Author:** ![tar.cf.xz](https://avatars.discourse-cdn.com/v4/letter/t/ee59a6/32.png) [@tar.cf.xz](https://discuss.python.org/u/tar.cf.xz)\
**Post date:** [August 5, 2026, 4:13am UTC](https://discuss.python.org/t/algebraic-effects-in-python/107957/4 "2026-08-05T04:13:17Z")

</div>

Thanks for the replies! I eventually came across this:

> **[GitHub - hnmr293/aleff: Algebraic effects for Python — deep and shallow,...](https://github.com/hnmr293/aleff)**
>
> Algebraic effects for Python — deep and shallow, stateful, composable, multi-shot handlers

I tried a small example that explores both states of a feature flag:

```python
from aleff import create_handler, effect

feature_enabled = effect("feature_enabled")

def checkout_total():
    shipping = 0 if feature_enabled("free_shipping") else 500
    return 3_000 + shipping

explore_both = create_handler(feature_enabled)

@explore_both.on(feature_enabled)
def _(resume, flag):
    return {"off": resume(False), "on": resume(True)}

print(explore_both(checkout_total))
# {'off': 3500, 'on': 3000}

```

This is the kind of multi-shot behavior I was looking for. Thanks again!
