NotRequired
NotRequired is a typing construct used with TypedDict in Python to indicate that a particular key in a dictionary type is optional. When a key is annotated with NotRequired, a dictionary conforming to the TypedDict may omit that key entirely, but if the key is present, its value must conform to the specified type.
NotRequired was introduced as part of PEP 655 and is available in Python 3.11 and later. Before
To use NotRequired, you declare a TypedDict class and annotate optional keys with NotRequired. For example,
NotRequired is supported by major type checkers such as Mypy and Pyright, with varying history of support