skillfed

multimethod

Multiple argument dispatching.

multimethod v2.1 4.1M downloads/30d#2,377 on PyPI316
Permissive license Apache-2.0 Active released

What it is and what it does

Multimethod is a pure Python library that adds multiple argument dispatching to functions through a decorator. It lets you define multiple implementations of the same function name, each handling different argument type combinations. When called, the library inspects argument types and routes to the matching implementation—or the closest match if an exact one isn't registered. It caches type lookups for speed and supports both simple type dispatch (using issubclass) and advanced generic types like Mapping, tuple, Iterable, and Callable with variance rules.

The library aims for simplicity and speed, offering two main modes: multimethod for faster cached positional-only dispatch, and multidispatch for compatibility with functools.singledispatch that also handles keyword arguments. It works with class methods, static methods, and custom metaclasses, and includes a subtype utility for isinstance and issubclass checks on generic types. No external dependencies are required.

Use it for:

  • Implement mathematical operations that behave differently for int vs float arguments without explicit type checking.
  • Build serializers that handle different data types (dict, list, custom objects) with specialized logic per type.
  • Create API handlers that dispatch to different implementations based on request payload type.
  • Define recursive algorithms where base cases and recursive cases are separated by argument type.
  • Extend third-party classes with new methods by registering multimethod implementations across inheritance hierarchies.

Worth the install?

AI-flagged interpretation of the facts on this page — verify before relying

Multimethod provides a decorator for adding multiple argument dispatching to functions, allowing you to define different implementations based on argument types with type-cached lookup.

Yes. Multimethod is actively maintained, has no dependencies, supports modern Python versions (3.11+), carries a permissive license, and solves a real problem—type-based function dispatch—with a clean API and documented performance trade-offs. It's suitable for production use.

Install

multimethod on PyPI

pip

pip install multimethod

uv

uv add multimethod

poetry

poetry add multimethod

Installing multimethod

Before you install

Low friction: pure Python wheel with no runtime dependencies. Actively maintained with recent release (16 days old) and 316 repository stars.

License in practice

Apache-2.0 permissive license allows commercial and private use with minimal restrictions.

Quickstart

from multimethod import multimethod

@multimethod
def func(x: int, y: float):
    return x + y

@multimethod
def func(x: float, y: int):
    return x * y

print(func(1, 2.0))  # calls first implementation
print(func(1.0, 2))  # calls second implementation

Requires Python 3.11 or later.

Verify before relying

  • Performance comparison with other multiple dispatch libraries on realistic workloads.
  • Whether caching strategy remains effective with complex generic type hierarchies.

Package facts

License Apache-2.0 (permissive)
Python support supports the current Python release (>=3.11)
Install friction low — pure-Python wheel
Runtime dependencies none
Maintenance actively maintained — 16 days since the last release
Last repo commit
First released
Downloads 4,117,958/month — #2,377 on PyPI (30-day window, as of 2026-08-14)
Known vulnerabilities none known (OSV.dev, checked 2026-08-14)

Evidence: multimethod-2.1-py3-none-any.whl

Keywords: multiple, dispatch, multidispatch, generic, functions, methods, overload

Development Status :: 5 - Production/StableIntended Audience :: DevelopersOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14Programming Language :: Python :: 3.15Topic :: Software Development :: Libraries :: Python ModulesTyping :: Typed

Tags

multiple dispatch decoratorfunction overloading by typemultimethod dispatchgeneric functions pythontype-based function routingsingledispatch alternativemultidispatch implementation
dispatchgeneric-functionstype-routing

More Python Modules packages