methoddispatch
singledispatch decorator for class methods.
What it is and what it does
methoddispatch extends Python's functools.singledispatchmethod to allow subclasses to maintain independent dispatch tables. The standard library's singledispatchmethod (added in Python 3.8) shares a dispatch registry across all subclasses, preventing subclasses from overriding type handlers without affecting the parent class. This package solves that by providing a SingleDispatch mixin that gives each class its own registry copy.
You decorate a method with @singledispatch and then register type-specific implementations using @method.register(type). When the method is called, it dispatches to the appropriate implementation based on the type of the first argument. Subclasses can extend or override the registry independently, and you can also register implementations at runtime via add_overload() or on individual instances. Type hints are supported for automatic type inference.
Use it for:
- Implement polymorphic behavior in class hierarchies where different subclasses need different type handlers without modifying parent dispatch tables.
- Create generic data processors that handle multiple input types (int, str, list, etc.) with specialized logic for each.
- Build plugin or strategy systems where handlers are registered by type and subclasses can add their own type handlers.
- Write serializers or formatters that dispatch on object type to produce different output representations.
- Develop type-aware method resolution in domain models where behavior depends on argument type rather than method name.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Adds single-dispatch method support to Python classes, allowing methods to dispatch on the type of their first argument with independent dispatch tables per subclass.
Yes, if you need independent dispatch tables in class hierarchies. The package solves a real limitation of functools.singledispatchmethod and has no dependencies. Dormant maintenance is acceptable here—the feature is stable and unlikely to need updates. Install it for polymorphic method dispatch; avoid it if you only need single-dispatch functions (use functools.singledispatch instead).
Install
methoddispatch on PyPI
pip
pip install methoddispatchuv
uv add methoddispatchpoetry
poetry add methoddispatchInstalling methoddispatch
Before you install
Low install friction with no runtime dependencies. Maintenance is dormant—last release was 2023-11-21 and no commits since then—but the package is stable and archived status is false, suggesting it is maintained as-is rather than abandoned.
License in practice
BSD license is permissive, allowing commercial and private use with minimal restrictions; suitable for most projects.
Quickstart
from methoddispatch import singledispatch, SingleDispatch
class MyClass(SingleDispatch):
@singledispatch
def process(self, arg):
print(arg)
@process.register(int)
def process_int(self, arg):
print(f"int: {arg}")
obj = MyClass()
obj.process(42) # dispatches to process_int
Verify before relying
- Whether the package works correctly with Python 3.12+ given the last release was 2023-11-21 and no explicit classifier for 3.12 is listed.
- Performance characteristics when dispatch registries grow large or when used in high-throughput scenarios.
Package facts
| License | BSD (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | dormant — 997 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 98,377/month — #13,088 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: methoddispatch-5.0.1-py3-none-any.whl
Keywords: single, dispatch, decorator, method
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
singledispatchProvides single-dispatch generic functions—a…
permissive · top 5,000 on PyPI
multimethodMultimethod provides a decorator for adding…
permissive · top 5,000 on PyPI
multipledispatchEnables functions to dispatch on the types of…
permissive · top 5,000 on PyPI
overloadingProvides function and method overloading based…
permissive · top 15,000 on PyPI
pyversPyvers provides dynamic dispatch for Python…
permissive · top 5,000 on PyPI
classesImplements typeclasses for Python, enabling…
permissive · top 15,000 on PyPI
json-encoderProvides JSON serialization with…
unclear · top 15,000 on PyPI
decoratorProvides utilities for writing function…
permissive · top 1,000 on PyPI
ovldOvld provides fast multiple dispatch for Python…
permissive · top 15,000 on PyPI
overridesProvides a @override decorator that validates…
permissive · top 1,000 on PyPI