singledispatch
Backport functools.singledispatch to older Pythons.
What it is and what it does
singledispatch is a backport of Python's functools.singledispatch decorator, which implements single-dispatch generic functions—a lightweight form of function overloading based on the type of the first argument. When you decorate a function with @singledispatch, you can register specialized implementations for specific types using the .register() method; at runtime, the dispatcher automatically calls the appropriate implementation based on the argument's type, falling back to the base implementation for unregistered types.
This is useful when you want to write cleaner, more maintainable code that handles multiple types without nested if-elif chains or isinstance checks scattered throughout. The backport allows you to use this functionality consistently across Python versions, and it also includes singledispatchmethod for class methods. Since the standard library version is built-in to Python 3.4+, this package is most valuable for codebases that need to support older Python versions or for projects that want to stay synchronized with the latest backport enhancements.
Use it for:
- Implement type-specific behavior in a library without explicit type checking or if-elif chains.
- Create a plugin system where different types are handled by different registered handlers.
- Build serializers or formatters that need different logic for different types.
- Simplify mathematical or data-processing functions that operate on multiple numeric types.
- Define class methods that dispatch on argument type in object-oriented designs.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Provides single-dispatch generic functions—a decorator-based mechanism to define functions that behave differently based on the type of their first argument—backported from Python 3.4's functools module for use on older Python versions.
Yes, if you need single-dispatch functionality on Python versions before 3.4 or want the latest backport enhancements. No, if you're on Python 3.4+ and can use functools.singledispatch directly from the standard library. The package is stable, well-maintained, has no known vulnerabilities, and carries no license friction.
Install
singledispatch on PyPI
pip
pip install singledispatchuv
uv add singledispatchpoetry
poetry add singledispatchInstalling singledispatch
Before you install
Low install friction; pure Python wheel with no runtime dependencies. Actively maintained by a CPython core team member with recent commits as of 2026-04-13.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open-source and proprietary projects with minimal restrictions.
Quickstart
pip install singledispatch
from singledispatch import singledispatch
@singledispatch
def process(arg):
print(f"Default: {arg}")
@process.register(int)
def _(arg):
print(f"Integer: {arg}")
process(arg)
Requires Python 3.9 or later.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.9) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 457 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 2,001,134/month — #3,372 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: singledispatch-4.1.2-py3-none-any.whl
Keywords: single, dispatch, generic, functions, singledispatch, genericfunctions, decorator, backport
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
methoddispatchAdds single-dispatch method support to Python…
permissive · top 15,000 on PyPI
multipledispatchEnables functions to dispatch on the types of…
permissive · top 5,000 on PyPI
simplegenericProvides a lightweight decorator-based system…
unclear · top 15,000 on PyPI
multimethodMultimethod provides a decorator for adding…
permissive · top 5,000 on PyPI
pyversPyvers provides dynamic dispatch for Python…
permissive · top 5,000 on PyPI
ovldOvld provides fast multiple dispatch for Python…
permissive · top 15,000 on PyPI
backports.functools-lru-cacheProvides the lru_cache decorator from Python…
permissive · top 5,000 on PyPI
functools32Backport of Python 3.2's functools module…
permissive · top 15,000 on PyPI
classesImplements typeclasses for Python, enabling…
permissive · top 15,000 on PyPI
pyeventsystempyeventsystem provides event-driven middleware…
permissive · top 15,000 on PyPI