{"id":23086,"library":"expression","title":"Expression","description":"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.","status":"active","version":"5.6.0","language":"python","source_language":"en","source_url":"https://github.com/dbrattli/Expression","tags":["functional-programming","monads","option","result","pipe"],"install":[{"cmd":"pip install expression","lang":"bash","label":"PyPI"}],"dependencies":[],"imports":[{"note":"Import path changed in v5.0.0; use top-level import.","wrong":"from expression.core import Option","symbol":"Option","correct":"from expression import Option"},{"note":"Import path changed in v5.0.0.","wrong":"from expression.core import Result","symbol":"Result","correct":"from expression import Result"},{"note":"pipe moved to top-level import in v5.0.0.","wrong":"from expression.core import pipe","symbol":"pipe","correct":"from expression import pipe"},{"note":"Try class is now a function try_ in v5.0.0+.","wrong":"from expression.core import Try","symbol":"try_","correct":"from expression import try_"},{"note":"effect moved to top-level import.","wrong":"from expression.core import effect","symbol":"effect","correct":"from expression import effect"}],"quickstart":{"code":"from expression import Option, Result, pipe\n\n# Option example\ndef safe_divide(a: float, b: float) -> Option[float]:\n    if b == 0:\n        return Option.Nothing()\n    return Option.Some(a / b)\n\n# Pipe usage\nresult = pipe(\n    Option.Some(10),\n    lambda x: x.map(lambda v: v * 2),\n    lambda x: x.bind(lambda v: safe_divide(v, 3))\n)\nprint(result)  # Option.Some(6.666...)\n\n# Result example\ndef fetch_user(id: int) -> Result[str, str]:\n    if id > 0:\n        return Result.Ok(f\"User {id}\")\n    return Result.Error(\"Invalid ID\")\n\nuser = fetch_user(1).map(lambda u: u.upper())\nprint(user)","lang":"python","description":"Basic usage of Option, Result, and pipe operator."},"warnings":[{"fix":"Replace 'from expression.core import ...' with 'from expression import ...'. For Try, use 'from expression import try_' as a function.","message":"v5.0.0 moved all core types to top-level imports (e.g., from expression import Option). Old imports from expression.core will break.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use 'try_' to wrap a callable. See quickstart for pattern.","message":"The Try type was replaced by the try_ function in v5.0.0. The class-based Try is gone.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use Option.match() or match statement (Python 3.10+): match option: case Option.Some(v): ... case Option.Nothing(): ...","message":"Option 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.","severity":"gotcha","affected_versions":"all"},{"fix":"Use either pipe(x, f, g) or x |> f |> g, but not both in the same chain.","message":"The pipe function supports starpipe (|>) operator style, but mixing pipe and starpipe can cause type errors. Prefer one style consistently.","severity":"deprecated","affected_versions":">=5.3.0"},{"fix":"Import as 'from expression import ...' and do not name any variable 'expression'.","message":"The expression package name conflicts with the 'expression' string. Avoid shadowing by importing with alias or using full qualified name.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Run 'pip install expression'. Delete any local file named expression.py.","cause":"Package not installed. Or conflicting module name if user created a file named expression.py.","error":"ModuleNotFoundError: No module named 'expression'"},{"fix":"Upgrade to latest: 'pip install --upgrade expression', and import from 'from expression import Option'.","cause":"Using old import path from expression.core, or installed an older version (<5.0.0).","error":"AttributeError: module 'expression' has no attribute 'Option'"},{"fix":"Use Result.Ok(value) or Result.Error(error). Do not call Result(value).","cause":"Calling Result as a function instead of using Result.Ok/Error constructors.","error":"TypeError: 'Result' object is not callable"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}