API Reference

class umapper.Case

Different types of case.

CAMEL is the case used in Java and JavaScript methods, somethingLikeThis(). SNAKE is usually utilized in C/C++ and Python methods, something_like_this(). PASCAL is CapitalCamelCase, often used in class names and Pascal derivatives. Kebab case is many times used in Scheme and other Lisp dialects, but was not included in this library

umapper.register_mapping_class(cls)

Registers classes that should be recursively mapped.

By default, umapper navigates dictionaries and built in sequences (lists and tuples), recursively mapping their contents. Often libraries offer utility classes that behave like dictionaries (mappings) but are not themselves either child classes of dictionaries nor inherit from collections.abc.Mapping. This method is used to register such classes, which must have a .items() method that iterates over its (key,value) entries.

Parameters:

cls (class) – class to register.

umapper.translate_case(value, desired_case)

Translate names of keys from dictionary-like (mapping) objects to a desired case.

Parameters:
  • value (dict-like) – mapping object to translate case.

  • deseired_case (int) – value of Case indicating what case to map to.

Returns:

a copy of the passed dictionary with the keys translated.

Return type:

dict

umapper.convert_to_object(value)

Transform dictionaries or dictionary-like objects into objects. The keys of the dictionary will become the fields of the newly generated object. This function will recursively convert the dictionary.

Parameters:

value (dict-like) – mapping object to convert to an object.

Returns:

raw object with the contents of the dictionary.

Return type:

object

umapper.assemble_dicts(*bases, include_nones=True, mapping_case=1, **named)

Merges dictionaries into one final dictionary. This method does a couple of things: firsly, it’ll merge separated dictionaties into one single dictionary, and if the same key is present in multiple dicts, the last ones will overwrite any previously processed key; secondly, it’ll convert the keys of the dictionaries to an specific case, which can be be configured by the key parameter ‘mapping_case’, which defaults to camel case; thirdly, it can skip including keys which have null values emplyoing the key parameter ‘include_nones’, that defaults to true; and lastly, any other key parameter will be included in the final result.

Parameters:
  • bases ([dict]) – list of dictionaries to merge/assemble.

  • include_nones (boolean) – whether to include keys with null values, defaults to true.

  • mapping_case (int) – which case to map the keys to, defaults to camel case.

  • named – any other key=value key parameter that should be included in the merged dict

Returns:

a dictionary with the list of dicts joined.

Return type:

dict