Skip to main content

Container Types: Dict

schema.dict

Declares a schema that can be any dict.

from d42 import schema

sch = schema.dict

schema.dict(keys)

Declares a schema for a dictionary. The contstructor takes a dictionary of key-value pairs, where the keys are strings representing the dictionary keys, and the values are schema objects representing the value types.

from d42 import schema

sch = schema.dict({
"id": schema.int.min(1),
"name": schema.str.len(1, ...)
})

By default, only the keys specified in the dictionary are allowed in the dictionary. To allow other keys, use the ... syntax:

from d42 import schema

sch = schema.dict({
"id": schema.int.min(1),
"name": schema.str.len(1, ...),
...: ...
})