--- id: classes version: "0.4.1" license: BSD-2-Clause license_treatment: permissive maintenance: dormant --- # classes — Smart, pythonic, ad-hoc, typed polymorphism for Python License: permissive · Maintenance: dormant · Downloads: 135.2K/mo ## 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 above — 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 pip install classes uv add classes 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_current - Install friction: low - Maintenance: dormant - Downloads: 135.2K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags typeclass polymorphism python, ad-hoc type dispatch, functional programming type safety, mypy plugin type classes, type-based method dispatch, pythonic polymorphism without inheritance, typed function overloading, functional-programming, type-dispatch, mypy-plugin [View on SkillFed](https://skillfed.io/packages/classes) · [View on PyPI](https://pypi.org/project/classes/)