multimethod
Multiple argument dispatching.
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 multimethoduv
uv add multimethodpoetry
poetry add multimethodInstalling 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
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
mixed-methodsProvides a decorator that lets a single method…
permissive · top 15,000 on PyPI
multipledispatchEnables functions to dispatch on the types of…
permissive · top 5,000 on PyPI
pyversPyvers provides dynamic dispatch for Python…
permissive · top 5,000 on PyPI
overloadingProvides function and method overloading based…
permissive · top 15,000 on PyPI
methoddispatchAdds single-dispatch method support to Python…
permissive · top 15,000 on PyPI
ovldOvld provides fast multiple dispatch for Python…
permissive · top 15,000 on PyPI
singledispatchProvides single-dispatch generic functions—a…
permissive · top 5,000 on PyPI
decoratorProvides utilities for writing function…
permissive · top 1,000 on PyPI
visitorProvides a base Visitor class to implement the…
permissive · top 15,000 on PyPI
runtypeRuntype provides runtime type validation,…
permissive · top 15,000 on PyPI