Is it possible to enforce the presence of certain keys but ignore all others? My use case is parsing JSON payloads from an event bus where I want to ignore fields that may be present but that I don't care to include in the TypedDict
.
This functionality would be similar to json-schema's additionalProperties: true
keyword.
For example:
from typing import TypedDict, NotRequired from trycast import trycast class MyType(TypedDict): a: str b: NotRequired[str | None] # currently fails validation because "c" is in the dict trycast(MyType, {"a": "foo", "b": "bar", "c": "baz"})
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4