Types#

EODAG types

eodag.types.__init__.json_field_definition_to_python(json_field_definition: Dict[str, Any], default_value: Optional[Any] = None, required: Optional[bool] = False) Any[source]#

Get python field definition from json object

>>> result = json_field_definition_to_python(
...     {
...         'type': 'boolean',
...         'title': 'Foo parameter'
...     }
... )
>>> str(result).replace('_extensions', '') # python3.8 compatibility
"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: Union[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, pydantic.fields.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)
>>> str(fields_definitions).replace('_extensions', '') # python3.8 compatibility
"{'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) Optional[Union[str, List[str]]][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