Utility Functions

arya_api_framework.utils.flatten_obj(obj)

Flattens a given object into a dict.

This is mainly used for arguments where a dict or a BaseModel can be accepted as parameters.

Parameters

obj (Optional[Union[dict, BaseModel]]) – The object or model to flatten into a dict format.

Returns

dict – A mapping of str keys to Any values.

arya_api_framework.utils.merge_dicts(base_dict, update_dict)

Merges the base dict with the update dict, overriding any of the base dict’s values with the updated values from the update dict.

Parameters
  • base_dict (Optional[dict]) – The default dict to update.

  • update_dict (Optional[dict]) – The new dict to update the base_dict from.

Returns

dict – A mapping of str to Union[str, int, float] containing the merged dictionaries.

arya_api_framework.utils.validate_type(obj, target, err=True)

Validates that a given parameter is of a type, or is one of a collection of types.

Parameters
  • obj (Any) – A variable to validate the type of.

  • target (Union[Type, List[Type]]) – A type, or list of types, to check if the param is an instance of.

  • err (bool) – Whether or not to throw an error if a type is not validated.

Returns

bool – A boolean representing whether the type was validated.