aiollm.serialization¶
serialization
¶
JSON codec, value formatting and request value normalization.
Modules:
| Name | Description |
|---|---|
json |
JSON codec used by default, backed by |
normalize |
Conversion of request values into wire-ready values. |
protocols |
Interfaces of request value encoding. |
traversal |
One guard against cycles and deep nesting for every value traversal. |
values |
Encoding of single request values: dates, durations and scalars. |
Classes:
| Name | Description |
|---|---|
IValueFormatter |
Turns dates, times and durations into the text an API expects. |
BaseValueFormatter |
Writes dates, times and durations in ISO 8601. |
Functions:
| Name | Description |
|---|---|
dumps |
Serialize |
loads |
Parse JSON. |
IValueFormatter
¶
Bases: Protocol
Turns dates, times and durations into the text an API expects.
A method declares one in __value_formatter__; every part of the
request (body, form, query and path) goes through it, so a value is
written the same way wherever it is sent.
Methods:
| Name | Description |
|---|---|
format_datetime |
Write a moment in time. |
format_date |
Write a calendar date. |
format_time |
Write a time of day. |
format_timedelta |
Write a duration. |
BaseValueFormatter
¶
Writes dates, times and durations in ISO 8601.
This is the format of date-time, date and time in JSON
Schema and OpenAPI, and the one Pydantic writes in JSON: a UTC moment
as 2026-01-02T03:04:05Z, another offset as +03:00, a duration
as PT30S. A provider whose API wants another format subclasses it
and overrides the methods it needs.
Methods:
| Name | Description |
|---|---|
format_datetime |
Write a moment in time in ISO 8601. |
format_date |
Write a calendar date in ISO 8601. |
format_time |
Write a time of day in ISO 8601. |
format_timedelta |
Write a duration in ISO 8601. |
format_datetime
¶
Write a moment in time in ISO 8601.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
datetime
|
A timezone-aware datetime. |
required |
Returns:
| Type | Description |
|---|---|
str
|
Its text, such as |
Raises:
| Type | Description |
|---|---|
ValueError
|
If the datetime is naive: the moment it names depends on the clock of whoever reads it. |