Install & Compatibility
Where this runs
tested against v5.6.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.262s · 18.8MB
glibcpy 3.10–3.95 runs
installs and imports cleanly · install 1.7s · import 0.238s · 19MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
Option
✓ from expression import Option
✗ from expression.core import Option
Import path changed in v5.0.0; use top-level import.
Result
✓ from expression import Result
✗ from expression.core import Result
Import path changed in v5.0.0.
pipe
✓ from expression import pipe
✗ from expression.core import pipe
pipe moved to top-level import in v5.0.0.
try_
✓ from expression import try_
✗ from expression.core import Try
Try class is now a function try_ in v5.0.0+.
effect
✓ from expression import effect
✗ from expression.core import effect
effect moved to top-level import.
Basic usage of Option, Result, and pipe operator.
from expression import Option, Result, pipe
# Option example
def safe_divide(a: float, b: float) -> Option[float]:
if b == 0:
return Option.Nothing()
return Option.Some(a / b)
# Pipe usage
result = pipe(
Option.Some(10),
lambda x: x.map(lambda v: v * 2),
lambda x: x.bind(lambda v: safe_divide(v, 3))
)
print(result) # Option.Some(6.666...)
# Result example
def fetch_user(id: int) -> Result[str, str]:
if id > 0:
return Result.Ok(f"User {id}")
return Result.Error("Invalid ID")
user = fetch_user(1).map(lambda u: u.upper())
print(user)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'expression'
Package not installed. Or conflicting module name if user created a file named expression.py.
fixRun 'pip install expression'. Delete any local file named expression.py.
AttributeError: module 'expression' has no attribute 'Option'
Using old import path from expression.core, or installed an older version (<5.0.0).
fixUpgrade to latest: 'pip install --upgrade expression', and import from 'from expression import Option'.
TypeError: 'Result' object is not callable
Calling Result as a function instead of using Result.Ok/Error constructors.
fixUse Result.Ok(value) or Result.Error(error). Do not call Result(value).
Upgrade
Version history
5.6.0latest on PyPI · released Feb 19, 2025
Audit
Dependencies
No dependency data recorded yet.