skillfed

multipledispatch

Multiple dispatch

multipledispatch v1.0.0 5.6M downloads/30d#2,072 on PyPI847
Permissive license BSD DORMANT released

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 multipledispatch

uv

uv add multipledispatch

poetry

poetry add multipledispatch

Installing 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

multiple dispatch decoratorfunction overloading by typemultimethod pythontype-based function dispatchpolymorphic function callsmethod resolution by argument typesgeneric functions python
polymorphismfunction-overloadingtype-dispatch

More Software Development packages