Package: dictmaper
With this library you can map your dictionaries easily, you just need to
pass it:1- output: the dictionary you want to receive, the variables you want to
map must go with {}fromDictMaperimportMapDictresult=MapDict(output={"{var_1}":"Hi!{var_2}, welcome to{company_name}""company name":"{company_name}"}......)2- context: context is the data from which the information will be
obtained:fromDictMaperimportMapDictresult=MapDict(output={"{var_1}":"Hi!{var_2}, welcome to{company_name}""company name":"{company_name}"}context={"user":{"name":"user name","email":"test_email@..."}"company":{"information":{"name":"Company name","id":"1234"}}})3- vars: vars are the variables you want to map to your output and the
value is where they are located within context:fromDictMaperimportMapDictresult=MapDict(output={"{var_1}":"Hi!{var_2}, welcome to{company_name}","company":"{company_name}"}context={"user":{"name":"user name","email":"test_email@..."},"company":{"information":{"name":"Company name","id":"1234"}}}vars={"var_1":"user.email","var_2":"user.name","company_name":"company.information.name"})That’s all, process the data making .process() and as a result you will
have:fromDictMaperimportMapDictresult=MapDict(...).process(){"test_email@...":"Hi! user name, welcome to Company name","company":"Company name"}```Ifyourcontextdictionarycontainsnesteddictionariesorlists,youcanusethisflagvariablecomplex_dict_mapping=Truetoprocessmorecomplexdictionaries.Butyoumusttakeintoaccountthefollowingrestrictions:1-Ifthe'context'dictionarycontainsakeywithalist,thenameofthekeymustbethesameinthe'vars'dictionaryandinthe'output'2-Youcanonlysearchatlevel1depthinthekeysthatcontainLISTSinthe'context'dictionary,wherethepathsdefinedinthe'variables'dictionarywillbesearched.3-Itisnotpossibletoplaceavariablefromthe'vars'dictionaryinthe'output'dictionaryasakeyinanyofthevalues​​ofthedictionariesthatarewithinsomelistthatarewithinthesame'output'dictionary.Example:1-output:thedictionaryyouwanttoreceive,thevariablesyouwanttomapmustgowith{}```pythonoutput={"contacts":[{"name":"{var_name}","email":"{var_email}","adresses":[{"main address":"{var_main_address}"}]}],"company name":"{company_name}"}2- context: context is the data from which the information will be
obtained:context={"contacts":[{"name":"user name","email":"test_email@...","address":{"main":"customer address"}},{"name":"user2 name2","email":"test2_email2@...","address":{"main":"customer address2"}}],"company":{"information":{"name":"Company name","id":"1234",}}}3- vars: vars are the variables you want to map to your output and the
value is where they are located within context:vars={"contacts":[{"var_name":"name","var_email":"email","var_main_address":"address.main",}],"company_name":"company.information.name",}That’s all, process the data doing .process() and as a result you will
have:
`python     from DictMaper import MapDict     result = MapDict(         output=output,         context=context,         vars=vars,          complex_dict_mapping=True     )     result.process()     {"contacts":[{"name":"username","email":"test_email@...","adresses":[{                     "mainaddress":"customeraddress"                     }                 ]             },             {"name":"user2name2","email":"test2_email2@...","adresses":[{                     "mainaddress":"customeraddress2"                     }                 ]             }         ],         "companyname":"Companyname"     }