How to assign vertex groups and bone weights through Blender's Python API?
vertex_groups method .add() first argument is a list of vertices index, I  group my input to reduce the calls to add to the minimum necessary.

Note: my input weights are stored in unsigned bytes (0-255).

First with a dict {grpID: ...} then another dict as value for weights {grpId: {weight: ...}}, finally the list of vertices id {grpId: {weight: [vxId, ...]}}, at this point the code is quite simple:

        weights = myGetWeights()
        for grpId, wv in weights.items():
            grpName = "Bone_"+str(grpId).zfill(3)
            ob.vertex_groups.new(grpName)
            for weight, vxIdList  in wv.items():
                ob.vertex_groups[grpName].add(vxIdList, 1.0 / 255 * weight, 'REPLACE')