{"id":22420,"library":"sumtypes","title":"sumtypes","description":"Provides algebraic data types (sum types / tagged unions) for Python, with pattern matching support, inspired by Rust and Haskell. Current version is 0.1a6 (alpha); no release cadence established.","status":"deprecated","version":"0.1a6","language":"python","source_language":"en","source_url":"https://github.com/radix/sumtypes","tags":["algebraic types","sum types","tagged unions","pattern matching","type safety"],"install":[{"cmd":"pip install sumtypes","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"note":"SumType is a class, not a submodule.","wrong":"import sumtypes.SumType","symbol":"SumType","correct":"from sumtypes import SumType"},{"note":"This is sumtypes.Enum, not stdlib enum.","wrong":"from enum import Enum","symbol":"Enum","correct":"from sumtypes import Enum"},{"note":"Case is used to define sum type variants.","wrong":null,"symbol":"Case","correct":"from sumtypes import Case"}],"quickstart":{"code":"from sumtypes import SumType, Case, Enum\n\nclass Status(SumType):\n    Active = Case()\n    Inactive = Case()\n    Pending = Case(str)\n\nstatuses = [Status.Active(), Status.Inactive(), Status.Pending(\"waiting\")]\nfor s in statuses:\n    if isinstance(s, Status.Active):\n        print(\"active\")\n    elif isinstance(s, Status.Inactive):\n        print(\"inactive\")\n    else:\n        print(f\"pending: {s.value}\")","lang":"python","description":"Define a sum type with three variants; pattern match using isinstance."},"warnings":[{"fix":"Migrate to 'adt' or 'union' library for actively maintained sum types.","message":"Library is in alpha (0.1a6) and appears unmaintained; last updated in 2015. Consider alternatives like 'union' or 'adt' for production use.","severity":"deprecated","affected_versions":"all"},{"fix":"Always check variant type via isinstance, not structural pattern matching.","message":"Avoid Python 3.10+ pattern matching (match/case) as it conflicts with sumtypes.Case naming. Use isinstance instead.","severity":"gotcha","affected_versions":"all"},{"fix":"If you need iteration, maintain a separate list of variants.","message":"sumtypes.Enum is not iterable and cannot be used like stdlib Enum. Do not call list() on it.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Add `from sumtypes import Case` to your imports.","cause":"Forgot to import Case from sumtypes.","error":"NameError: name 'Case' is not defined"},{"fix":"Use `Status.Active()` to create an instance.","cause":"Trying to call Status() directly instead of a variant (e.g., Status.Active()).","error":"TypeError: Can't instantiate abstract class Status without an implementation"},{"fix":"Only access .value on variants with parameters; use isinstance to determine variant first.","cause":"Accessing .value on a variant that doesn't carry data (e.g., an empty Case).","error":"AttributeError: 'Status' object has no attribute 'value'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}