skillfed

methoddispatch

singledispatch decorator for class methods.

methoddispatch v5.0.1 98.4K downloads/30d#13,088 on PyPI5
Permissive license BSD DORMANT released

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 methoddispatch

uv

uv add methoddispatch

poetry

poetry add methoddispatch

Installing 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

License :: OSI Approved :: BSD LicenseProgramming Language :: PythonProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9

Tags

single dispatch decorator methodstype-based method overloadinggeneric methods pythonsingledispatch for class methodsmethod dispatch by typepolymorphic method dispatch
method-dispatchpolymorphism

More Software Development packages