Registry / serialization / ovld
library0.5.17pypypi✓ verified 21d ago

Ovld is a Python library that provides fast and feature-rich multiple dispatch for functions using type annotations. Unlike Python's built-in `functools.singledispatch`, `ovld` supports dispatching on multiple arguments, custom predicates, and value-based dispatch. It aims to simplify code that would otherwise rely on complex `if-elif` chains or `isinstance` checks for different argument types. The library is actively maintained, with the current version being 0.5.15, and offers performance superior to other multiple dispatch libraries.

pip install ovld
INSTALL
IMPORT
SIG · OVLD
O
ovld
serializationpythonv0.5.17
Install
1.6s avg
Import
71ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.17 · 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.078s · 18.1MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.064s · 19MB
16MB installed
● package 16MB
Code
Verified usage

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

ovld
from ovld import ovld
recurse
from ovld import ovld, recurse
Used for variant-aware recursive calls within overloaded functions.
Dependent
from ovld.dependent import Dependent
For creating value-dependent types for dispatching.
Literal
from typing import Literal
Commonly used with ovld for dispatching on specific values.

This quickstart demonstrates basic function overloading for different types and argument counts. It also includes an example of recursive dispatch using `recurse`, which is essential for ensuring that nested calls respect `ovld`'s dispatch mechanism and any defined variants.

from ovld import ovld, recurse from typing import Literal @ovld def process(x: str): return f"Processing string: {x!r}" @ovld def process(x: int): return f"Processing integer: {x}" @ovld def process(x: int, y: int): return f"Processing two integers: {x}, {y}" @ovld def process(x: Literal[0]): return "Special case: zero" # Example of recursive overload @ovld def add_nested(x: list, y: list): return [recurse(a, b) for a, b in zip(x, y)] @ovld def add_nested(x: int, y: int): return x + y assert process("hello") == "Processing string: 'hello'" assert process(10) == "Processing integer: 10" assert process(1, 2) == "Processing two integers: 1, 2" assert process(0) == "Special case: zero" assert add_nested([1, 2], [3, 4]) == [4, 6] assert add_nested([1, [2]], [3, [4]]) == [4, [6]]
Debug
Known issues
gotchaWhen defining recursive `ovld` functions, always use `recurse(...)` instead of directly calling the function by its name (e.g., `my_func(...)`). `recurse` is specially designed to work with `ovld`'s variant system, ensuring that recursive calls correctly dispatch to the appropriate variant of the current `ovld` object. Direct calls will bypass this mechanism.
fix
Replace direct recursive calls (e.g., `my_func(a, b)`) with `recurse(a, b)` inside `@ovld` decorated functions.
affects: All versions
gotchaDependent types created with `ovld.dependent.Dependent` require a type bound as their first argument (e.g., `Dependent[int, lambda n: n > 0]`). The provided check function is applied to the *value* of the argument at runtime, not its static type. Incorrectly specifying the type bound or the check predicate can lead to unexpected dispatch behavior or runtime errors.
fix
Ensure the first argument to `Dependent` is a valid Python type that acts as a bound, and the second argument is a callable predicate that operates on the argument's value.
affects: All versions
gotchaWhen using `ovld` to dispatch on generic collection types (e.g., `list[str]`), `ovld` currently only checks the type of the *first element* of the collection. It does not perform a full validation of all elements within the collection against the generic type parameter. This can lead to a dispatch if the first element matches, even if subsequent elements do not.
fix
Be aware of this limitation and implement additional runtime checks if strict validation of all elements in generic collections is required, or define more specific overloads.
affects: All versions
gotchaThe `postprocess` argument in the `@ovld` decorator (or `ovld.dispatch`) only applies to the *top-level* call of the overloaded function. Intermediate recursive calls made via `recurse()` will *not* have their results processed by the `postprocess` function.
fix
If intermediate results need processing, wrap the `recurse()` calls explicitly or define custom dispatch logic instead of relying solely on `postprocess`.
affects: All versions
Errors
Common errors & fixes
TypeError: Ambiguous call to 'function_name'
This error occurs when multiple `@ovld` decorated functions have signatures that equally match the arguments provided, making it impossible for `ovld` to determine the most specific or appropriate function to call.
fix
To resolve this, define a more specific `@ovld` overload that exactly matches the ambiguous call's argument types, or refine existing overloads to ensure a clear hierarchy and specificity.
ImportError: cannot import name 'ovld' from 'ovld'
This usually indicates a typo in the import statement or an attempt to import a specific component (like 'ovld' or 'OvldMC') that might be misspelled or not directly available under that name from the top-level `ovld` package.
fix
Verify the spelling of `ovld` and other components you are trying to import (e.g., `OvldMC`). The main decorator is typically `ovld` and the metaclass is `OvldMC`.
RuntimeError: No matching overloads found for 'function_name'
This error signifies that the arguments passed to an `@ovld` decorated function do not match the type annotations or predicates of any of the defined overloads for that particular function.
fix
Inspect the arguments being passed and the `@ovld` definitions. Either adjust the arguments to conform to an existing overload's signature, or define a new `@ovld` overload with a signature (type annotations and/or predicates) that correctly matches the argument types being provided.
TypeError: isinstance() argument 2 cannot be a parameterized generic.
This Python runtime error occurs when `isinstance()` or `issubclass()` is used with a parameterized generic type (e.g., `list[int]`, `Iterable[str]`). While `ovld` uses type annotations for dispatch, direct runtime checks with parameterized generics in custom predicates or other logic are not supported by Python's built-in `isinstance`.
fix
Instead of `isinstance(obj, list[int])`, use `typing.get_origin()` and `typing.get_args()` to inspect generic types at runtime if you need to check both the base type and its parameters. Alternatively, leverage `ovld`'s built-in support for generic collections which handles checks like `list[str]` by inspecting the first element or overall type.
Upgrade
Version history
0.5.17latest on PyPI · released May 14, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
7 hits · last 30 days
node
6
Resources
ovld — pip install ovld · libregistry