--- id: multimethod version: "2.1" license: Apache-2.0 license_treatment: permissive maintenance: active --- # multimethod — Multiple argument dispatching. License: permissive · Maintenance: active · Downloads: 4.1M/mo ## 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 above — 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 pip install multimethod uv add multimethod 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_current - Install friction: low - Maintenance: active - Downloads: 4.1M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags multiple dispatch decorator, function overloading by type, multimethod dispatch, generic functions python, type-based function routing, singledispatch alternative, multidispatch implementation, dispatch, generic-functions, type-routing [View on SkillFed](https://skillfed.io/packages/multimethod) · [View on PyPI](https://pypi.org/project/multimethod/)