multipledispatch
Multiple dispatch
What it is and what it does
multipledispatch is a pure-Python library that implements multiple dispatch—a way to select which version of a function to call based on the types of all its arguments, not just the first one. You decorate different implementations of the same function with @dispatch(type1, type2, ...) to register them, and the library automatically routes calls to the right implementation at runtime.
It handles inheritance, instance methods, union types (e.g., int or float), and abstract base classes. It caches lookups for speed and detects ambiguities at definition time to warn you about conflicts. The library has no external dependencies and is lightweight, making it suitable for codebases that need polymorphic behavior without heavyweight frameworks.
Use it for:
- Implement mathematical operations that behave differently for different numeric types (int, float, complex) without nested type checks.
- Build domain-specific APIs where methods dispatch on argument types to provide specialized behavior for different data structures.
- Create generic algorithms that adapt their behavior based on whether inputs are sequences, iterables, or scalar values.
- Simplify code that would otherwise use isinstance() chains or a type-based lookup dictionary.
- Support plugin systems where different handlers register implementations for different argument type combinations.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Enables functions to dispatch on the types of multiple arguments, allowing you to define different implementations for the same function name based on argument types.
Yes, if you need multiple dispatch and want a lightweight, dependency-free solution. The library is stable and well-established (since 2014), though dormant—last updated 2023-06-27. It has no known vulnerabilities and is widely used (top 5000 on PyPI). Suitable for production use in projects that benefit from type-based polymorphism without the overhead of heavier frameworks.
Install
multipledispatch on PyPI
pip
pip install multipledispatchuv
uv add multipledispatchpoetry
poetry add multipledispatchInstalling multipledispatch
Before you install
Installs with no dependencies beyond the standard library. Maintenance is dormant—last release was 2023-06-27, over 1144 days ago—but the repository remains active with recent commits and no archived status, suggesting it is stable rather than abandoned.
License in practice
Licensed under BSD (permissive), so you can use, modify, and distribute it freely in both open and closed projects with minimal restrictions.
Quickstart
pip install multipledispatch
from multipledispatch import dispatch
@dispatch(int, int)
def add(x, y):
return x + y
@dispatch(object, object)
def add(x, y):
return f"{x} + {y}"
print(add(1, 2)) # 3
print(add(1, 'hello')) # 1 + hello
Verify before relying
- Whether the package works with modern Python versions (requires_python is unspecified in the fact sheet).
- Performance characteristics when handling hundreds of type signatures (documentation notes this becomes troublesome but does not quantify the threshold).
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 1,144 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 5,566,231/month — #2,072 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: multipledispatch-1.0.0-py3-none-any.whl
Keywords: dispatch
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
multimethodMultimethod provides a decorator for adding…
permissive · top 5,000 on PyPI
overloadingProvides function and method overloading based…
permissive · top 15,000 on PyPI
plum-dispatchPlum implements multiple dispatch in Python,…
permissive · top 5,000 on PyPI
singledispatchProvides single-dispatch generic functions—a…
permissive · top 5,000 on PyPI
methoddispatchAdds single-dispatch method support to Python…
permissive · top 15,000 on PyPI
classesImplements typeclasses for Python, enabling…
permissive · top 15,000 on PyPI
ovldOvld provides fast multiple dispatch for Python…
permissive · top 15,000 on PyPI
pyversPyvers provides dynamic dispatch for Python…
permissive · top 5,000 on PyPI
etuplesProvides S-expression emulation using…
permissive · top 5,000 on PyPI
logical-unificationLogical unification in Python with support for…
permissive · top 5,000 on PyPI