runtype
Type dispatch and validation for run-time Python
What it is and what it does
Runtype is a pure-Python type system for runtime validation and dispatch. It provides three main capabilities: a validation layer (`isa`, `issubclass`) that understands `typing` module constructs and constraints; an enhanced dataclass decorator that validates and optionally casts field values at instantiation; and a multiple-dispatch decorator that routes function calls to the most specific type-matching implementation.
The package is designed for developers who need runtime type safety without external C dependencies. It supports forward references, generic types, and custom type constraints. The dataclass mode can auto-cast values (like Pydantic) and sample large collections for faster validation. All three modules are built on an internal type system that the documentation claims outperforms comparable libraries like Pydantic v1 and beartype in pure-Python benchmarks.
Use it for:
- Add runtime type validation to dataclasses with automatic value casting and constraint checking.
- Implement multiple-dispatch functions that route to different implementations based on argument types.
- Validate complex nested types (e.g., `dict[str, list[int]]`) at runtime without external type checkers.
- Build custom type systems with generics and phantom types for domain-specific validation.
- Replace `isinstance` checks with smarter type validation that understands `typing` module annotations.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Runtype provides runtime type validation, dataclass enhancement with type checking, and multiple-dispatch function routing based on argument types, all without external dependencies.
Yes. Runtype is actively maintained, has no dependencies, supports current Python versions (3.8+), carries no known vulnerabilities, and offers a cohesive toolkit for runtime type validation and dispatch. Install it if you need runtime type safety in dataclasses or want to use multiple dispatch without external dependencies. The permissive MIT license removes any legal friction.
Install
runtype on PyPI
pip
pip install runtypeuv
uv add runtypepoetry
poetry add runtypeInstalling runtype
Before you install
Installation is straightforward with no runtime dependencies. The package is actively maintained with a recent release on 2025-03-03 and an active repository.
License in practice
MIT license permits unrestricted use, modification, and distribution in both open and closed-source projects.
Quickstart
pip install runtype
from runtype import isa, dataclass, multidispatch as md
assert isa({'a': 1}, dict[str, int])
@dataclass(check_types='cast')
class Person:
name: str
p = Person('Alice')
@md
def process(x: int):
return x * 2
@md
def process(x: str):
return x.upper()
process(5) # Returns 10
Requires Python 3.8 or later.
Verify before relying
- Whether the claimed performance advantage over Pydantic v1 and other type checkers holds across all use patterns and Python versions.
- Compatibility and behavior with Python 3.13+ given the current support ceiling.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (<4.0,>=3.8) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | actively maintained — 529 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 649,116/month — #5,578 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: runtype-0.5.3-py3-none-any.whl
Keywords: types, typing, dispatch, multimethods, dataclass, runtime
Tags
More Python Modules packages
Converts domain names between Unicode and…
permissive · top 100 on PyPI
setuptoolsSetuptools is a Python build backend and…
permissive · top 100 on PyPI
PyYAMLPyYAML parses and emits YAML 1.1 data format,…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
annotated-typesProvides reusable metadata objects for use with…
permissive · top 100 on PyPI
typing-inspectionProvides runtime tools to inspect and…
permissive · top 100 on PyPI
ovldOvld provides fast multiple dispatch for Python…
permissive · top 15,000 on PyPI
undictifyEnforces type annotations at runtime by…
permissive · top 15,000 on PyPI
sumtypesProvides algebraic data types for Python,…
permissive · top 15,000 on PyPI
phantom-typesPhantom types enable you to create type-safe…
permissive · top 15,000 on PyPI
multimethodMultimethod provides a decorator for adding…
permissive · top 5,000 on PyPI
typed-json-dataclassAdds JSON serialization and type validation to…
permissive · top 15,000 on PyPI
plum-dispatchPlum implements multiple dispatch in Python,…
permissive · top 5,000 on PyPI
overloadingProvides function and method overloading based…
permissive · top 15,000 on PyPI
typing-inspectProvides runtime inspection utilities for…
permissive · top 1,000 on PyPI
dataclass-csvReads and writes CSV files using Python…
permissive · top 15,000 on PyPI