Skip to content
You're viewing docs for v2.3. See the latest version →

Types/callables

typing.Callable : see below for more detail on parsing and validation

Fields can also be of type Callable:

from typing import Callable

from pydantic import BaseModel


class Foo(BaseModel):
    callback: Callable[[int], int]


m = Foo(callback=lambda x: x)
print(m)
#> callback=<function <lambda> at 0x0123456789ab>