simplegeneric
Simple generic functions (similar to Python's own len(), pickle.dump(), etc.)
What it is and what it does
simplegeneric is a minimal single-dispatch generic function library that lets you define functions that behave differently based on the type or identity of their first argument. You decorate a base function with @generic, then register type-specific or object-specific implementations using @func.when_type() or @func.when_object() decorators. When the function is called, it looks up and invokes the appropriate implementation based on the argument's type, falling back to the default if no match is found.
The library is intentionally simple—under 100 lines of code with no dependencies—and uses lookup tables similar to pickle.dump() and other standard library generic functions. It supports inheritance (methods defined for supertypes are inherited via MRO), multiple type/object registration in a single decorator, and inspection methods like has_type() and has_object(). However, it is abandoned (last release April 2012) and predates Python's built-in functools.singledispatch by several years.
Use it for:
- Implementing a visitor-like pattern where different object types need different handling without modifying the objects themselves.
- Creating a simple type-based dispatch system for serialization, formatting, or conversion routines.
- Building extensible functions where new type handlers can be registered at runtime without changing the core function.
- Legacy codebases that already depend on simplegeneric and cannot easily migrate to functools.singledispatch.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides a lightweight decorator-based system for defining single-dispatch generic functions that route calls based on the type or identity of their first argument.
No. The package is abandoned (no maintenance since 2012) and its Python 3 support is undocumented and untested. Modern Python (3.4+) includes functools.singledispatch, which is actively maintained and serves the same purpose. The unclear license treatment and high install friction add further risk. Install only if you are maintaining legacy code that already depends on it and cannot migrate to functools.singledispatch.
Install
simplegeneric on PyPI
pip
pip install simplegenericuv
uv add simplegenericpoetry
poetry add simplegenericInstalling simplegeneric
Before you install
High install friction due to source distribution format. Package is abandoned (last release 2012-04-01, no maintenance for 5248 days) and carries only Python 2 classifiers despite claiming Python 3 compatibility in its description.
License in practice
Licensed under Zope Public License 2.1 (ZPL 2.1), but license treatment is marked unclear—verify compatibility with your project's license requirements before use.
Quickstart
from simplegeneric import generic
@generic
def process(item):
return "default"
@process.when_type(int)
def _(item):
return f"integer: {item}"
print(process(42)) # integer: 42
print(process("text")) # default
Package is abandoned and has not been maintained since 2012; Python 3 support is undocumented and untested in the repository.
Verify before relying
- Whether Python 3 compatibility actually works as claimed in the description, given the package's age and lack of maintenance.
- Current status of ZPL 2.1 license compatibility with modern open-source projects and commercial use.
- Whether the package's single-dispatch model is sufficient for modern use cases or if functools.singledispatch (Python 3.4+) is a better alternative.
Package facts
| License | ZPL 2.1 (unclear) |
| Python support | not specified |
| Install friction | high — source build required |
| Runtime dependencies | none |
| Maintenance | abandoned — 5,248 days since the last release |
| First released | |
| Downloads | 561,418/month — #5,996 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: simplegeneric-0.8.1.zip
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
overloadingProvides function and method overloading based…
permissive · top 15,000 on PyPI
visitorProvides a base Visitor class to implement the…
permissive · top 15,000 on PyPI
singledispatchProvides single-dispatch generic functions—a…
permissive · top 5,000 on PyPI
classesImplements typeclasses for Python, enabling…
permissive · top 15,000 on PyPI
singleton-decoratorProvides a decorator that enforces singleton…
copyleft · top 15,000 on PyPI
typishTypish provides runtime type checking and…
permissive · top 5,000 on PyPI
multimethodMultimethod provides a decorator for adding…
permissive · top 5,000 on PyPI
decoratorProvides utilities for writing function…
permissive · top 1,000 on PyPI
overridesProvides a @override decorator that validates…
permissive · top 1,000 on PyPI
methoddispatchAdds single-dispatch method support to Python…
permissive · top 15,000 on PyPI