Value
pydantic_pint.value ¶
Defines the Pydantic compatible wrapper for an instance of pint.Quantity.
pydantic_pint_value_schema ¶
The schema that can serialize a pint.Quantity.
| RETURNS | DESCRIPTION |
|---|---|
SchemaSerializer | The serializer schema for Pydantic. |
Source code in src/pydantic_pint/value.py
inject_pydantic_schema ¶
Adds the Pydantic serializer schema to a Pint quantity.
| PARAMETER | DESCRIPTION |
|---|---|
quantity | The Pint quantity. TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Quantity | The same Pint quantity with a pydantic schema. |
Source code in src/pydantic_pint/value.py
pydantic_pint_value ¶
Construct pint.Quantity with an injected Pydantic serialization schema.
A serialization schema is added to a Pint quantity to allow it to be serialized by pydantic. This in-turn allows Pint values to be used in a pydantic.Field context.
| PARAMETER | DESCRIPTION |
|---|---|
value | The magnitude of the quantity. TYPE: |
units | The units of the quantity. Defaults to unitless quantity. TYPE: |
ureg | The unit registry from which to create the quantity. Defaults to TYPE: |
| RETURNS | DESCRIPTION |
|---|---|
Quantity | A |
Source code in src/pydantic_pint/value.py
PydanticPintValue ¶
Proxy class for a Pint Quantity instance with pydantic serialization.
Warning
The name PydanticPintQuantity is deprecated. Use pydantic_pint_value instead.
Unlike PydanticPintQuantity, PydanticPintValue wraps an instance of a pint quantity. Methods are added to allow it to interact with pydantic, e.g. serialization. The class immediately resolves to a pint.Quantity upon construction. The primary use for PydanticPintValue is in pydantic.Field comparison restrictions.
See pydantic_pint_value for more details.