Skip to main content

Effectful

Effectful is an algebraic effect system for Python, intended for use in the implementation of probabilistic programming languages. It is a core component of the ChiRho causal modeling language.

Installation

Install From Source

git clone git@github.com:BasisResearch/effectful.git
cd effectful
git checkout master
pip install -e .[pyro]

Install With Optional PyTorch/Pyro Support

effectful has optional support for:

  • PyTorch (tensors with named dimensions)

  • Pyro (wrappers for Pyro effects)

  • Jax (tensors with named dimensions)

  • Numpyro (operations for Numpyro distributions)

To enable PyTorch support:

pip install effectful[torch]

Pyro support (which includes PyTorch support):

pip install effectful[pyro]

Jax support:

pip install effectful[jax]

Numpyro support (which includes Jax support):

pip install effectful[numpyro]

Getting Started

Here’s an example demonstrating how effectful can be used to implement a simple DSL that performs arithmetic on terms with free variables.

import functools

from effectful.ops.types import Term
from effectful.ops.syntax import defdata, defop
from effectful.ops.semantics import handler, evaluate, coproduct, fwd

add = defdata.dispatch(int).__add__

def beta_add(x: int, y: int) -> int:
    match x, y:
        case int(), int():
            return x + y
        case _:
            return fwd()

def commute_add(x: int, y: int) -> int:
    match x, y:
        case Term(), int():
            return y + x
        case _:
            return fwd()

def assoc_add(x: int, y: int) -> int:
    match x, y:
        case _, Term(op, (a, b)) if op == add:
            return (x + a) + b
        case _:
            return fwd()

beta_rules = {add: beta_add}
commute_rules = {add: commute_add}
assoc_rules = {add: assoc_add}

eager_mixed = functools.reduce(coproduct, (beta_rules, commute_rules, assoc_rules))

We can represent free variables as operations with no arguments, generated using defop:

>>> x = defop(int, name="x")
>>> y = defop(int, name="y")

If we evaluate an expression containing free variables, we get a term:

>>> e = 1 + 1 + (x() + 1) + (5 + y())
>>> print(e)
add(2, add(add(x(), 1), add(5, y())))

We can make the evaluation strategy smarter by taking advantage of the commutativity and associativity of addition, as expressed by the commute_add and assoc_add handlers.

>>> with handler(eager_mixed):
>>>     print(evaluate(e))
add(8, add(x(), y()))

Using with AI Agents

A standalone Markdown reference for building effectful LLM applications is published with each documentation build. Point your AI coding agent (e.g. Claude Code, Cursor, Copilot) to:

https://basisresearch.github.io/effectful/llm.md

This file is auto-generated from the LLM tutorial notebook and contains complete API usage examples for templates, tool calling, structured output, retries, and more.

Learn More

More examples and API documentation can be found in the docs.

Metadata

Release files for effectful 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for effectful 0.4.0
File Size Uploaded Provenance Actions
effectful-0.4.0.tar.gz 205.4 kB Without provenance Details for effectful-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for effectful 0.4.0
File Interpreter ABI Platform Actions
effectful-0.4.0-py3-none-any.whl Python 3 none any Details for effectful-0.4.0-py3-none-any.whl

Total release size: 315.0 kB

Release files / effectful-0.4.0.tar.gz

Download URL effectful-0.4.0.tar.gz
Size 205.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e280c4048928a2760aaf4d8845c06adc0d1038a6fcb835ba146572a18d03308b
BLAKE2b-256 checksum
How to use checksums
b4e639abdc35d8486e5df3b627134f43f0010a06af181492f3d273dfaa954f3c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Release files / effectful-0.4.0-py3-none-any.whl

Download URL effectful-0.4.0-py3-none-any.whl
Size 109.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
321d70723c75d8284ce6e22870538e7ade29efdd771c89e62fa832da49cb31e5
BLAKE2b-256 checksum
How to use checksums
67edb8d858c4990ac54ea4eb3c695e75a3ee6a9af5e7b75b83d377d5a9ed9a32
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.25

Security for effectful 0.4.0

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.

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