I have this model: So I want to be able to take requests like: and Right now in the second case I get using this code: So how can I exclude n_processes here? Answer You can use exclude_none param of Pydantic’s model.dict(…): Output: Also, it’s more idiomatic to write Optional[int] instead of Union[int, None].
Tag: optional-parameters
How to check whether optional function parameter is set
Is there an easy way in Python to check whether the value of an optional parameter comes from its default value, or because the user has set it explicitly at the function call? Answer Lot of answers have little pieces of the full info, so I’d like to bring it all together with my favourite pattern(s). default value is a