NEWS

Checks whether a Python value broadly matches a type hint without recursively validating collections or changing the value.

On this page 3 sections

Python type hints say what kind of value a function or setting expects. At runtime, however, the built-in isinstance() cannot directly check hints such as “an integer or None” or list[str]. Plugin registration, configuration, and function selection often need only a quick yes-or-no compatibility check—not a complete inspection or conversion of the value.

A local helper gives each project different rules. Typeguard, Beartype, and Pydantic solve a broader problem: they inspect nested values, enforce types, or convert data. That can be more than a quick yes-or-no check needs.

simtypes is a dependency-free Python library for this specific check. Its single check() function understands ordinary classes, alternatives such as int | str, optional values, Any, None, and the outer container named by hints such as list[str]. The release is available on GitHub.

Supported runtime checks

The library exposes check(type, value) -> bool, with the type argument first:

from simtypes import check

check(int, 42)                    # True
check(int | None, None)           # True
check(list[str], [1, 2, 3])       # True

The last result is intentional: list[str] checks only whether the value is a list. Ordinary classes use isinstance; Any, None, unions, optionals, and parameterized outer types have explicit rules.

Collection cost therefore does not grow with length, but simtypes cannot validate untrusted nested data or a complete static annotation.

There are no required dependencies, decorators, import interception, data conversion, or schemas: callers receive a boolean and decide what it means.

Comparison with full validation tools

The broader tools above are better for complete validation. Runtype, for example, checks collections recursively; simtypes deliberately does not.

A local helper may be enough for one call site. simtypes is useful when several libraries must share and test the same policy.

Intended use

simtypes is for internal code that needs a quick compatibility decision while a program is running. Function selection, plugin registration, and configuration can share one rule without adopting a complete validation framework.