QamoosTech
Programming FundamentalsTypes and typingIntermediatePython

TypedDict

PronunciationTYPT dikt

Definition

A TypedDict describes the shape of a dictionary: which keys it has and what type each value is. At runtime it is still a normal dictionary.

Where you hear it

In Python projects that handle JSON-like data, and in type-checking discussions.

Examples

  • The API response is typed as a TypedDict with a name and a list of tags.
  • The checker warns if you read a key that is not in the TypedDict.
  • The config is a TypedDict, so the checker catches a typo in any of its keys.

Common mistake

Expecting a TypedDict to validate data when the program runs. It only helps the type checker; use a validation library for real input.

Don't confuse with

A dataclass, which creates real objects with attributes. A TypedDict stays a plain dictionary.

Say it at work

  • In a meeting or chatUse a TypedDict to describe the JSON we receive.
  • In an email or ticketAdd the missing key to the TypedDict so the checker passes.