--- id: multipledispatch version: "1.0.0" license: BSD license_treatment: permissive maintenance: dormant --- # multipledispatch — Multiple dispatch License: permissive · Maintenance: dormant · Downloads: 5.6M/mo ## 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 above — 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 pip install multipledispatch uv add multipledispatch 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: unspecified - Install friction: low - Maintenance: dormant - Downloads: 5.6M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags multiple dispatch decorator, function overloading by type, multimethod python, type-based function dispatch, polymorphic function calls, method resolution by argument types, generic functions python, polymorphism, function-overloading, type-dispatch [View on SkillFed](https://skillfed.io/packages/multipledispatch) · [View on PyPI](https://pypi.org/project/multipledispatch/)