cfdibills.io.normalize_dict_keys

cfdibills.io.normalize_dict_keys(ugly_dict: dict) dict[source]

Maps the raw keys of a xmlschema to human-readable keys.

xmlschema returns a dict with keys that:

  • begin with “@” when they are leaf nodes

  • begin with “cfdi:”, “tfd:” or similar when they are nodes

  • contain “xmlns” and “xsi” when are namespace definition

  • are written in camelCase as defined by SAT’s xsd

So all of these are normalized to plain snake_case strings

Some special cases:

  • if the item is a Decimal, map it to a float python number

  • if the item is a dictionary, normalize its children

  • if it is an array, normalize every item in it

Parameters

ugly_dict (dict) – Dictionary as output from xmltodict

Returns

Dictionary with keys in camel_case format

Return type

dict