--- id: sumtypes version: "0.1a6" license: MIT license_treatment: permissive maintenance: abandoned --- # sumtypes — Algebraic types for Python (notably providing Sum Types, aka Tagged Unions) License: permissive · Maintenance: abandoned · Downloads: 187.0K/mo ## What it is and what it does sumtypes brings algebraic data types to Python by implementing sum types (also called tagged unions), which let you define a type with multiple named constructor variants. Each variant can carry its own set of attributes. The package builds on attrs to provide attribute validation, defaults, and other features. You decorate a class with @sumtype, define constructors as class attributes, and then instantiate them by calling those constructors; the resulting objects track which constructor was used and can be pattern-matched over all cases. The main use case is writing code that handles multiple distinct cases of a logical type in a type-safe, exhaustive way. Instead of using strings or integers to tag variants, sum types make the structure explicit and let the match decorator verify that all cases are handled. This is particularly useful in functional programming styles or when modeling domain logic with multiple states or alternatives. Use it for: - Model domain types with multiple variants such as Result as Success or Failure, or AST nodes with different expression types - Write exhaustive pattern-matching functions over all constructor cases without risk of missing a case - Define state machines or state enums where each state can carry different associated data - Implement functional-style error handling with explicit Success and Error constructors - Build parsers or interpreters that need to represent different kinds of syntax tree nodes ## Worth the install? AI-flagged interpretation of the facts above — verify before relying. Provides algebraic data types for Python, specifically sum types (tagged unions) that let you define and pattern-match over multiple constructor variants of a single type. No. The package is abandoned (last commit 2021-11-30, no activity for 1718 days), and maintenance compatibility with current Python versions is unverified. For new projects, consider whether native language features or actively maintained alternatives better serve your needs. ## Install pip install sumtypes uv add sumtypes poetry add sumtypes ## Installing sumtypes Before you install: Low install friction with a single runtime dependency on attrs. However, the package is abandoned as of 2021-11-30 with no commits since then, so maintenance and compatibility with modern Python versions are concerns. License in practice: MIT license is permissive, allowing commercial and private use with minimal restrictions. Quickstart: pip install sumtypes from sumtypes import sumtype, constructor, match @sumtype class Color(object): Red = constructor() Green = constructor() Blue = constructor('intensity') red = Color.Red() blue = Color.Blue(42) @match(Color) class describe(object): def Red(): return 'red' def Green(): return 'green' def Blue(intensity): return 'blue' Verify before relying: - Whether the package works reliably with modern Python versions given its abandoned status since 2021-11-30 - Whether attrs version compatibility has drifted and could cause runtime issues - Whether pattern matching remains the recommended approach or if newer Python versions offer better alternatives ## Package facts - License: MIT (permissive) - Python support: unspecified - Install friction: low - Maintenance: abandoned - Downloads: 187.0K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags algebraic data types python, sum types tagged unions, pattern matching python, tagged union implementation, constructor variants python, functional programming types, enum-like discriminated unions, algebraic-types, pattern-matching, functional-programming [View on SkillFed](https://skillfed.io/packages/sumtypes) · [View on PyPI](https://pypi.org/project/sumtypes/)