sumtypes
Algebraic types for Python (notably providing Sum Types, aka Tagged Unions)
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 on this page — 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
sumtypes on PyPI
pip
pip install sumtypesuv
uv add sumtypespoetry
poetry add sumtypesInstalling 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 | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 1 — attrs |
| Maintenance | abandoned — 1,718 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 187,040/month — #9,972 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: sumtypes-0.1a6-py2.py3-none-any.whl
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
oslashOSlash implements functional programming…
permissive · top 15,000 on PyPI
runtypeRuntype provides runtime type validation,…
permissive · top 15,000 on PyPI
numeraryProvides runtime-checkable protocols and type…
permissive · top 15,000 on PyPI
ExpressionExpression provides functional programming…
permissive · top 5,000 on PyPI
itypesProvides immutable container types (Dict and…
permissive · top 5,000 on PyPI
amplpyamplpy is a Python interface to AMPL, an…
permissive · top 15,000 on PyPI
typing-inspectProvides runtime inspection utilities for…
permissive · top 1,000 on PyPI
pampyPampy provides pattern matching for Python,…
permissive · top 15,000 on PyPI
jsonsConverts Python objects (dataclasses, attrs…
permissive · top 5,000 on PyPI
symenginePython wrappers for SymEngine, a fast C++…
permissive · top 15,000 on PyPI