Registry / serialization / plum-dispatch

plum-dispatch

JSON →
library2.9.0pypypi✓ verified 22d ago

Plum-dispatch is a Python library that provides a powerful and Pythonic implementation of multiple dispatch, allowing functions to behave differently based on the types of multiple arguments. Its design philosophy is inspired by Julia's approach to multiple dispatch, and version 2.x is powered by the `beartype` library for enhanced performance. The library is actively maintained, with its current version being 2.8.0, and has seen consistent updates.

pip install plum-dispatch
INSTALL
IMPORT
SIG · PLUM-DISPATCH
P
plum-dispatch
serializationpythonv2.9.0
Install
3.1s avg
Import
470ms
Disk
39MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.9.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.492s · 39.9MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.1s · import 0.448s · 41MB
39MB installed
● package 39MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

dispatch
from plum import dispatch
from plum.dispatch import dispatch
As of Plum 2.6.1, all imports should go through the top-level `plum` package directly.

Demonstrates defining multiple versions of a function using the `@dispatch` decorator, where the appropriate implementation is chosen based on the runtime type of the arguments. It also highlights the restriction on using positional arguments for dispatch.

from numbers import Number from plum import dispatch @dispatch def process(x: str): return f"Processing string: {x}" @dispatch def process(x: int): return f"Processing integer: {x}" @dispatch def process(x: Number): return f"Processing a generic number: {x}" assert process("hello") == "Processing string: hello" assert process(123) == "Processing integer: 123" assert process(1.0) == "Processing a generic number: 1.0" try: process(x=123) # This will fail due to keyword argument dispatch rule except Exception as e: print(f"Caught expected error: {type(e).__name__}: {e}")
Debug
Known issues
breakingPlum (version 2.x) relies on positional arguments for dispatch. Keyword arguments are explicitly NOT used in the decision-making for which method to call. Positional arguments without a default value must always be given positionally.
fix
Always pass arguments that determine dispatch as positional arguments. Avoid passing them as keyword arguments where dispatch is expected.
affects: 2.0.0+
breakingImport paths have changed. All imports for Plum's public API should now go directly through the `plum` package (e.g., `from plum import dispatch`). Sub-module imports are no longer recommended or supported.
fix
Update all import statements to use `from plum import <symbol>` instead of `from plum.submodule import <symbol>`.
affects: 2.6.1+
breakingPlum 2.x dropped support for Python 3.9.
fix
Ensure your project runs on Python 3.10 or higher to use Plum 2.x.
affects: 2.0.0+
gotchaUsing parametric types (e.g., `List[int]`, `Tuple[str, int]`) for dispatch can incur a significant performance hit due to the need to check every element's type.
fix
Use parametric types judiciously and only where absolutely necessary. Profile your code if performance becomes a concern.
affects: All
gotchaPlum is often recommended over `multipledispatch` due to being more featureful, having better support for class inheritance, and correctly handling method precedence (choosing the most specific method).
fix
If migrating from `multipledispatch`, be aware of potential behavior differences and leverage Plum's advanced features.
affects: All
Errors
Common errors & fixes
NotFoundLookupError: For function "f", signature Signature(builtins.float) could not be resolved.
This error occurs when `plum-dispatch` cannot find a suitable method for the types of the arguments provided, either because no dispatch has been defined for those specific types or a more general fallback, or because arguments intended for dispatch were passed as keyword arguments.
fix
Ensure that a `@dispatch` method is defined for the argument types being passed (or a suitable superclass). For arguments that `plum-dispatch` needs to dispatch on, ensure they are passed positionally, not as keyword arguments.
NameError: name 'Real' is not defined
This is a standard Python issue where a type hint refers to a class that is not yet fully defined (e.g., a class using itself in a type hint within its own body).
fix
Use string forward references for type hints (e.g., `other: "Real"`) to defer the evaluation of the type hint until the class is fully defined.
TypeError: No promotion rule for "builtins.int" and "builtins.float".
This error occurs when `plum-dispatch` attempts to perform an operation (like addition) between two different numeric types (e.g., `int` and `float`) for which a specific type promotion rule has not been explicitly defined.
fix
Define a type promotion rule for the involved types using `plum.add_promotion_rule(type_from_a, type_from_b, type_to_promote_to)`.
TypeError: Test.__call__() got an unexpected keyword argument 'a'.
This error can arise when using `plum-dispatch` with class methods, especially in scenarios involving decorators or how arguments are handled within the class's `__call__` method, potentially exacerbated by the integration with `beartype` in Plum 2.x.
fix
Review the class method definition and how `plum-dispatch` is applied. Ensure arguments are correctly passed according to the dispatched method's signature and that any custom `__call__` implementations align with `plum-dispatch`'s argument handling.
Upgrade
Version history
2.9.0latest on PyPI · released Apr 28, 2026
Audit
Dependencies
beartyperequiredPlum 2.x is powered by Beartype for instance-check-based dispatch and performance.
richrequiredUsed for rich text and terminal output.
typing-extensionsrequiredProvides backports of features for the `typing` module.
Agent activity
9 hits · last 30 days
node
6
Resources
plum-dispatch — pip install plum-dispatch · libregistry