skillfed

runtype

Type dispatch and validation for run-time Python

runtype v0.5.3 649.1K downloads/30d#5,578 on PyPI175
Permissive license MIT Active released

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 runtype

uv

uv add runtype

poetry

poetry add runtype

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3Programming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software Development :: Libraries :: Python ModulesTopic :: Software Development :: Quality AssuranceTopic :: Utilities

Tags

runtime type validationtype dispatch functionsdataclass type checkingmultiple dispatch decoratortyping module validationruntime type constraintsfast type checking
type-validationmultiple-dispatchdataclass-enhancement

More Python Modules packages