You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have searched Google & GitHub for similar requests and couldn't find anything
I have read and followed the docs and still think this feature is missing
Description
Current pydantic supports datetime.datetime type, serialization as {type: string, format: date-time}.
De-serialisation of this type includes coercion from integer in ms or seconds since epoch as well.
Serialization is limited to iso-format as string.
I propose to create a new type, Epoch {type: integer, format: date-time} to be used for unix timestamps which gets serialized to integer and has proper semantics for the schema.
I currently use an Annotated datetime, the schema generated does not match the value, it's ugly, incomplete and carrying this to multiple projects is building tomorrows technical debt.
Having Epoch as a standard data type would improve usability for pydantic at a minimal cost.
Initial Checks
Description
Current pydantic supports datetime.datetime type, serialization as {type: string, format: date-time}.
De-serialisation of this type includes coercion from integer in ms or seconds since epoch as well.
Serialization is limited to iso-format as string.
I propose to create a new type, Epoch {type: integer, format: date-time} to be used for unix timestamps which gets serialized to integer and has proper semantics for the schema.
I currently use an Annotated datetime, the schema generated does not match the value, it's ugly, incomplete and carrying this to multiple projects is building tomorrows technical debt.
Having Epoch as a standard data type would improve usability for pydantic at a minimal cost.
Affected Components
.model_dump()
and.model_dump_json()
model_construct()
, pickling, private attributes, ORM modeThe text was updated successfully, but these errors were encountered: