Match shape key index and a driver index
I figured out a way of how to get a name of the bone that is driving a shape key. Although it is a bit hacky and it does work for only the first target in the driver. Also I abandoned the idea of trying to match the shape key index and the driver index. Now I use the shape key name to get the index of the driver if that makes sense.
import bpy

selected_shape_key_collection = bpy.context.object.active_shape_key.id_data.name
selected_shape_key_index = bpy.context.object.active_shape_key_index
selected_shape_key_name = bpy.context.object.active_shape_key.name


name_list = []
for x in bpy.context.object.active_shape_key.id_data.animation_data.drivers:
    #Hacky because I don't know how to get just the raw names so I used .replace
    name = x.data_path.replace('key_blocks[&quot;',&quot;&quot;).replace('&quot;].value',&quot;&quot;)
    name_list.append(name)

if selected_shape_key_name not in name_list:
    print(&quot;No&quot;)
else:
    driver_index = name_list.index(selected_shape_key_name)
    print(bpy.data.shape_keys[selected_shape_key_collection].id_data.animation_data.drivers[driver_index].driver.variables[0].targets[0].bone_target)