Registry / serialization / expression

expression

JSON →
library5.6.0pypypi✓ verified 85d ago

A functional programming library for Python 3.10+ providing immutable data structures like Option, Result, Try, and pipe operators. Version 5.6.0 is the latest, with active maintenance and frequent releases.

pip install expression
INSTALL
IMPORT
SIG · EXPRESSION
E
expression
serializationpythonv5.6.0
Install
1.7s avg
Import
313ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
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
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.262s · 18.8MB
glibc
py 3.103.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)
Debug
Known issues
breakingv5.0.0 moved all core types to top-level imports (e.g., from expression import Option). Old imports from expression.core will break.
fix
Replace 'from expression.core import ...' with 'from expression import ...'. For Try, use 'from expression import try_' as a function.
affects: >=5.0.0
breakingThe Try type was replaced by the try_ function in v5.0.0. The class-based Try is gone.
fix
Use 'try_' to wrap a callable. See quickstart for pattern.
affects: >=5.0.0
gotchaOption and Result are not ordinary Python booleans. Do not use if option: to check for Some/Nothing; use option.match or pattern matching introduced in later versions.
fix
Use Option.match() or match statement (Python 3.10+): match option: case Option.Some(v): ... case Option.Nothing(): ...
affects: all
deprecatedThe pipe function supports starpipe (|>) operator style, but mixing pipe and starpipe can cause type errors. Prefer one style consistently.
fix
Use either pipe(x, f, g) or x |> f |> g, but not both in the same chain.
affects: >=5.3.0
gotchaThe expression package name conflicts with the 'expression' string. Avoid shadowing by importing with alias or using full qualified name.
fix
Import as 'from expression import ...' and do not name any variable 'expression'.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'expression'
Package not installed. Or conflicting module name if user created a file named expression.py.
fix
Run '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).
fix
Upgrade 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.
fix
Use 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.

Agent activity
2 hits · last 30 days
node
2
Resources
expression — pip install expression · libregistry