Typing and Generics

typing.TypedDict

Describes dictionaries with known string keys and per-key static value types. Instances are ordinary dictionaries; neither construction nor assignment validates the schema. total controls default requiredness.

Formal Syntax & Structure

python syntaxpython
class Name(typing.TypedDict, total=True): ...

Return Value

TypedDict class

Typing construct or runtime result as described; static typing rules are not runtime validation.

Working Example

Example Snippetpython
from typing import TypedDict
class Product(TypedDict):    name: str    price: intitem = Product(name='pen',price=3)print((item['name'], item['price'], type(item) is dict))
Python Reference