skillfed

simplegeneric

Simple generic functions (similar to Python's own len(), pickle.dump(), etc.)

simplegeneric v0.8.1 561.4K downloads/30d#5,996 on PyPI
License unclear ZPL 2.1 Abandoned released

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 simplegeneric

uv

uv add simplegeneric

poetry

poetry add simplegeneric

Installing 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

Development Status :: 6 - MatureDevelopment Status :: 7 - InactiveIntended Audience :: DevelopersLicense :: OSI Approved :: Zope Public LicenseOperating System :: OS IndependentProgramming Language :: PythonProgramming Language :: Python :: 2Programming Language :: Python :: 2.4Programming Language :: Python :: 2.5Programming Language :: Python :: 2.6Programming Language :: Python :: 2.7Programming Language :: Python :: 3Topic :: Software Development :: Libraries :: Python Modules

Tags

single dispatch generic functionstype-based function dispatchgeneric function decoratormethod registration by typevisitor pattern alternative
abandonedlegacydispatch

More Python Modules packages