classes
Smart, pythonic, ad-hoc, typed polymorphism for Python
Decision gist · record as of 2026-08-14
Yes, with conditions. Install if you need ad-hoc polymorphism without inheritance and are comfortable with dormant maintenance (last release 2022-04-11). The package is stable, has no known vulnerabilities, and low install friction. Not recommended if you require active upstream support or need assurance of mypy plugin compatibility with the latest type-checker versions.AI-flagged interpretation of the facts on this page — verify before relying
Before you install
- Requires mypy plugin configuration in setup.cfg or mypy.ini under [mypy] with 'plugins = classes.contrib.mypy.classes_plugin' for full type safety; without it, type violations will be reported.
- Low friction install with a single runtime dependency (typing_extensions).
- Maintenance is dormant—last release was 2022-04-11, over 1586 days ago, though the repository remains active with a recent commit on 2024-12-17.
License · maintenance · safety
BSD-2-Clause (permissive) — BSD-2-Clause is permissive and imposes minimal restrictions. You can use, modify, and distribute this package freely in commercial and private projects provided you include the license notice.
last release 2022-04-11 (1586 days) · last repo commit 2024-12-17 · 731 stars
0 known vulnerabilities (OSV.dev, 2026-08-14) · 135,192 downloads/mo, #11,450 on PyPI
Alternatives
Verify before relying
pip install classes
from classes import typeclass
@typeclass
def to_json(instance) -> str:
"""Convert things to json."""
@to_json.instance(int)
def _to_json_int(instance: int) -> str:
return str(instance)
result = to_json(value)- Whether the mypy plugin remains compatible with recent mypy versions given the package's dormant status since 2022.
- Real-world performance characteristics when dispatching on complex type hierarchies or with many registered instances.
What it is and what it does
Classes provides a typeclass system for Python—a way to bind behavior to types without creating class hierarchies or interfaces. Instead of writing many subclasses (like IntField, BoolField, etc.), you define a typeclass as a function and register implementations for specific types using decorators. This approach reduces boilerplate, improves type safety through mypy integration, and makes it easier to extend behavior for new types without modifying existing code.
The package is designed for declarative, functional-style business logic where different data types need different handling. A common use case is serialization (converting objects to JSON based on their type), but it applies anywhere you'd otherwise use a type-based dispatch pattern. It requires mypy plugin configuration to achieve full type safety; without it, the type checker will report violations.
Use it for
- Implement serialization/deserialization logic that varies by type (e.g., custom JSON converters for int, bool, datetime).
- Build validation rules that apply different checks to different data types without inheritance chains.
- Create extensible handler registries where third-party code can add support for custom types.
- Write functional-style data transformation pipelines where operations dispatch based on input type.
- Reduce boilerplate in libraries that need type-specific behavior (like ORMs or REST frameworks).
Worth the install?
AI-flagged interpretation of the facts on this page. Verify before relying on it.
Yes, with conditions.
Install if you need ad-hoc polymorphism without inheritance and are comfortable with dormant maintenance (last release 2022-04-11). The package is stable, has no known vulnerabilities, and low install friction. Not recommended if you require active upstream support or need assurance of mypy plugin compatibility with the latest type-checker versions.
Install
classes on PyPI
Before you install
Low friction install with a single runtime dependency (typing_extensions). Maintenance is dormant—last release was 2022-04-11, over 1586 days ago, though the repository remains active with a recent commit on 2024-12-17. Suitable for stable, mature use cases but not for projects requiring active upstream support.
Requires mypy plugin configuration in setup.cfg or mypy.ini under [mypy] with 'plugins = classes.contrib.mypy.classes_plugin' for full type safety; without it, type violations will be reported.
License in practice
BSD-2-Clause is permissive and imposes minimal restrictions. You can use, modify, and distribute this package freely in commercial and private projects provided you include the license notice.
Quickstart
pip install classes
from classes import typeclass
@typeclass
def to_json(instance) -> str:
"""Convert things to json."""
@to_json.instance(int)
def _to_json_int(instance: int) -> str:
return str(instance)
result = to_json(value)
Verify before relying
- Whether the mypy plugin remains compatible with recent mypy versions given the package's dormant status since 2022.
- Real-world performance characteristics when dispatching on complex type hierarchies or with many registered instances.
Package facts
| License | BSD-2-Clause permissive |
| Python support | Supports the current Python release >=3.7,<4.0 |
| Install friction | Low. Pure-Python wheel |
| Runtime dependencies | 1 packagetyping_extensions |
| Maintenance | Dormant 1,586 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 135,192 / month, #11,450 on PyPI 30-day window, as of 2026-08-14 |
| Known vulnerabilities | None known OSV.dev, checked 2026-08-14 |
| Classifiers | Development Status :: 4 - BetaIntended Audience :: DevelopersLicense :: OSI Approved :: BSD LicenseOperating System :: OS IndependentProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTopic :: Utilities |
Evidence: classes-0.4.1-py3-none-any.whl
Tags
Let your AI agent find packages like this
Example. Real query, live index.
You found this page by searching. An agent finds it by wishing: SkillFed indexes 14,416 PyPI packages by what they can do, searchable in plain language.
wish › “typeclass polymorphism python”
- classesImplements typeclasses for Python, enabling type-based dispatch and…
- marshmallow-polyfieldExtends Marshmallow with a PolyField class that handles serialization…
- marshmallow-oneofschemaExtends marshmallow to handle polymorphic serialization and…
Give your agent the search over MCP, or paste the wish link into any chat.
More Python Modules packages
Converts domain names between Unicode and ASCII-compatible encoding (Punycode) according to IDNA 2008 and Unicode Technical Standard 46, with security validation and broader script coverage than the standard library.
Install it if you work with internationalized domain names, need to validate domains, or use HTTP clients that depend on it transitively.
Setuptools is a Python build backend and package management tool that handles building, distributing, and installing Python packages, including support for C/C++ extension modules.
PyYAML parses and emits YAML 1.1 data format, enabling serialization and deserialization of configuration files and Python objects to and from human-readable YAML text.
Pydantic validates Python data structures against type hints, coercing and checking input at runtime to ensure it matches a declared schema.
Provides reusable metadata objects for use with PEP-593 `typing.Annotated` to express common constraints like bounds, collection sizes, and predicates on types.
Install it if you use or build libraries that need to express type constraints in a standardized, inspectable way—or if you want to annotate your own types with…
Provides runtime tools to inspect and introspect Python type annotations, enabling programmatic examination of type hints at execution time.
See also fasttransform · overloading · multipledispatch · visitor · simplegeneric · methoddispatch · plum-dispatch · singledispatch · returns · mypy-zope