--- id: singledispatch version: "4.1.2" license: MIT license_treatment: permissive maintenance: active --- # singledispatch — Backport functools.singledispatch to older Pythons. License: permissive · Maintenance: active · Downloads: 2.0M/mo ## 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 above — 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 pip install singledispatch uv add singledispatch poetry add singledispatch ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 2.0M/month (top 5,000 on PyPI) - Known vulnerabilities: none known ## Tags single dispatch decorator, generic functions by type, functools singledispatch backport, method overloading python, type-based function dispatch, generic-functions, decorator, backport [View on SkillFed](https://skillfed.io/packages/singledispatch) · [View on PyPI](https://pypi.org/project/singledispatch/)