Types#
EODAG types
- class eodag.types.__init__.ProviderSortables[source]#
A class representing sortable parameter(s) of a provider and the allowed maximum number of used sortable(s) in a search request with the provider
- eodag.types.__init__.json_field_definition_to_python(json_field_definition: Dict[str, Any], default_value: Any | None = None, required: bool | None = False) Any [source]#
Get python field definition from json object
>>> result = json_field_definition_to_python( ... { ... 'type': 'boolean', ... 'title': 'Foo parameter' ... } ... ) >>> res_repr = str(result).replace('_extensions', '') # python3.8 compatibility >>> res_repr = res_repr.replace(', default=None', '') # pydantic >= 2.7.0 compatibility >>> res_repr "typing.Annotated[bool, FieldInfo(annotation=NoneType, required=False, title='Foo parameter')]"
- Parameters:
json_field_definition – the json field definition
default_value – default value of the field
required – if the field is required
- Returns:
the python field definition
- eodag.types.__init__.json_type_to_python(json_type: str | List[str]) type [source]#
Get python type from json type https://spec.openapis.org/oas/v3.1.0#data-types
>>> json_type_to_python("number") <class 'float'>
- Parameters:
json_type – the json type
- Returns:
the python type
- eodag.types.__init__.model_fields_to_annotated(model_fields: Dict[str, FieldInfo]) Dict[str, Any] [source]#
Convert BaseModel.model_fields from FieldInfo to Annotated
>>> from pydantic import create_model >>> some_model = create_model("some_model", foo=(str, None)) >>> fields_definitions = model_fields_to_annotated(some_model.model_fields) >>> fd_repr = str(fields_definitions).replace('_extensions', '') # python3.8 compatibility >>> fd_repr = fd_repr.replace(', default=None', '') # pydantic >= 2.7.0 compatibility >>> fd_repr "{'foo': typing.Annotated[str, FieldInfo(annotation=NoneType, required=False)]}"
- Parameters:
model_fields – BaseModel.model_fields to convert
- Returns:
Annotated tuple usable as create_model argument
- eodag.types.__init__.python_field_definition_to_json(python_field_definition: Any) Dict[str, Any] [source]#
Get json field definition from python typing.Annotated
>>> from pydantic import Field >>> from eodag.utils import Annotated >>> python_field_definition_to_json( ... Annotated[ ... Optional[str], ... Field(None, description='Foo bar', json_schema_extra={'$ref': '/path/to/schema'}) ... ] ... ) {'type': ['string', 'null'], 'description': 'Foo bar', '$ref': '/path/to/schema'}
- Parameters:
python_field_annotated – the python field annotated type
- Returns:
the json field definition
- eodag.types.__init__.python_type_to_json(python_type: type) str | List[str] | None [source]#
Get json type from python https://spec.openapis.org/oas/v3.1.0#data-types
>>> python_type_to_json(int) 'integer' >>> python_type_to_json(Union[float, str]) ['number', 'string']
- Parameters:
python_type – the python type
- Returns:
the json type