skillfed

classes

Smart, pythonic, ad-hoc, typed polymorphism for Python

classes v0.4.1 135.2K downloads/30d#11,450 on PyPI731
Permissive license BSD-2-Clause DORMANT released

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

Implements typeclasses for Python, enabling type-based dispatch and polymorphic behavior without inheritance or interfaces, with full mypy support.

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

pip

pip install classes

uv

uv add classes

poetry

poetry add classes

Installing classes

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.

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)

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.

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 — typing_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)

Evidence: classes-0.4.1-py3-none-any.whl

Keywords: functional programming, fp, type class, typeclass, typeclasses, ad-hoc, composition, type-safety, mypy, stubs

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

Tags

typeclass polymorphism pythonad-hoc type dispatchfunctional programming type safetymypy plugin type classestype-based method dispatchpythonic polymorphism without inheritancetyped function overloading
functional-programmingtype-dispatchmypy-plugin

More Python Modules packages