Typing Inspect
raw JSON → 0.9.0 verified Tue May 12 auth: no python install: verified quickstart: verified
typing-inspect is a Python library providing runtime inspection utilities for types defined in the standard `typing` module. It is currently at version 0.9.0, is actively maintained, and compatible with Python 3.6 and later. It offers an easy-to-use API for advanced introspection of type hints.
pip install typing-inspect Warnings
breaking The API of `typing-inspect` is still considered experimental. While generally stable, breaking changes might occur in future versions. Users should consult the changelog for specific updates. ↓
fix Always pin the `typing-inspect` version in your `requirements.txt` or `pyproject.toml` to ensure consistent behavior across deployments.
gotcha There exists another, distinct library named `typing-inspection` (used by Pydantic) which provides similar runtime typing introspection tools. Ensure you are importing from `typing_inspect` (underscore) for this library, not `typing_inspection` (hyphen). ↓
fix Double-check your `pip install` command (`pip install typing-inspect`) and import statements (`import typing_inspect` or `from typing_inspect import ...`) to ensure you are using the correct package.
gotcha The `get_args` function, when called with `evaluate=True`, can be computationally expensive in terms of both time and memory. This option performs all type parameter substitutions. ↓
fix Avoid using `get_args(tp, evaluate=True)` in performance-critical paths unless strictly necessary. The default `evaluate=False` reports results as nested tuples and is generally more performant.
gotcha `typing-inspect` is designed to work with the latest versions of the Python `typing` module and `typing-extensions`. Older or specific versions of these dependencies might lead to unexpected behavior or unsupported types. ↓
fix Ensure your project's `typing` and `typing-extensions` dependencies are up-to-date or meet the minimum versions specified by `typing-inspect` (currently `typing>=3.7.4` and `typing-extensions>=3.7.4`).
Install compatibility verified last tested: 2026-05-12
python os / libc status wheel install import disk
3.10 alpine (musl) wheel - 0.03s 18.2M
3.10 alpine (musl) - - 0.03s 18.2M
3.10 slim (glibc) wheel 1.5s 0.02s 19M
3.10 slim (glibc) - - 0.02s 19M
3.11 alpine (musl) wheel - 0.06s 20.1M
3.11 alpine (musl) - - 0.07s 20.1M
3.11 slim (glibc) wheel 1.7s 0.05s 21M
3.11 slim (glibc) - - 0.05s 21M
3.12 alpine (musl) wheel - 0.05s 11.9M
3.12 alpine (musl) - - 0.05s 11.9M
3.12 slim (glibc) wheel 1.5s 0.05s 12M
3.12 slim (glibc) - - 0.06s 12M
3.13 alpine (musl) wheel - 0.04s 11.7M
3.13 alpine (musl) - - 0.05s 11.6M
3.13 slim (glibc) wheel 1.5s 0.05s 12M
3.13 slim (glibc) - - 0.05s 12M
3.9 alpine (musl) wheel - 0.02s 17.7M
3.9 alpine (musl) - - 0.03s 17.7M
3.9 slim (glibc) wheel 1.8s 0.02s 18M
3.9 slim (glibc) - - 0.02s 18M
Imports
- is_generic_type
from typing_inspect import is_generic_type - get_args
from typing_inspect import get_args - get_origin
from typing_inspect import get_origin - is_union_type
from typing_inspect import is_union_type - is_optional_type
from typing_inspect import is_optional_type
Quickstart verified last tested: 2026-04-23
from typing import List, Union, Optional, TypeVar
from typing_inspect import is_generic_type, get_args, get_origin, is_optional_type
T = TypeVar('T')
class MyGeneric(List[T]):
pass
# Example 1: Check if a type is generic
assert is_generic_type(MyGeneric[int]) # This should be True
assert not is_generic_type(int) # This should be False
# Example 2: Get arguments of a type
args = get_args(List[str])
assert args == (str,)
union_type = Union[int, str]
union_args = get_args(union_type)
assert set(union_args) == {int, str}
# Example 3: Get the origin of a type
origin = get_origin(List[int])
assert origin is list
# Example 4: Check for optional types
assert is_optional_type(Optional[int])
assert not is_optional_type(int)
print("All quickstart assertions passed!")