runtype is composed of several utility modules:
dispatch - Provides a decorator for fast multi-dispatch at run-time for functions, with sophisticated ambiguity resolution.
dataclass - Improves on Python's existing dataclass, by verifying the type-correctness of its attributes at run-time. Also provides a few useful methods for dataclasses.
isa - Provides alternative functions to
issubclass, that understand Python's
Runtype's integration with the
typing module allows to use type signatures such as
Union[int, str, Callable].
Click on each one to learn more.
$ pip install runtype
Requires Python 3.7 or up (or Python 3.6 with the dataclasses backport)
Type verification in classes introduces a slight run-time overhead.
Multiple-dispatch caches call-signatures by default (disable at your own risk!), and should add a minimal overhead after the initial resolution. Dispatch is only 5 to 8 times slower than adding two numbers (see: examples/benchmark_dispatch), which is negligable.
Runtype is not recommended for use in functions that are called often in time-critical code (or classes that are created often).
Runtype uses the MIT license.
- typical - Provides type verification for classes and methods, with a focus on type coercion.