Modify driver target (or any property) I have a shape key which is controlled by a driver. The driver was created manualy by the user. How would I get the target of the driver from the shape key?
I know how to make a driver for a shape key:
import bpy

#Defines the selected shape key index.
selected_shape_key_index = bpy.context.object.active_shape_key_index

#Defines the selected shape key name.
selected_shape_key_name = bpy.context.object.active_shape_key.name

#Defines the selected shape key collection.
selected_shape_key_id = bpy.context.object.active_shape_key.id_data.name

#Defines active object name.
active_object_name = bpy.context.active_object.name


meshKey = bpy.data.meshes[active_object_name].shape_keys
valDrive = meshKey.key_blocks[selected_shape_key_name].driver_add('value')

valDrive.driver.type = 'AVERAGE'
drvVar = valDrive.driver.variables.new()
drvVar.name = 'DriverName'
drvVar.type = 'TRANSFORMS'
drvVar.targets[0].id = bpy.data.objects['Armature']
drvVar.targets[0].bone_target = 'ShapeKeyController_L'
drvVar.targets[0].transform_space = 'LOCAL_SPACE'
drvVar.targets[0].transform_type = 'LOC_Y'


print(&quot;target name is&quot;, drvVar.targets[0].bone_target)

But I don't know how to edit/read an existing driver. I thought that it would be something like this but it is not:
import bpy

#Defines the selected shape key index.
selected_shape_key_index = bpy.context.object.active_shape_key_index

#Defines the selected shape key name.
selected_shape_key_name = bpy.context.object.active_shape_key.name

#Defines the selected shape key collection.
selected_shape_key_id = bpy.context.object.active_shape_key.id_data.name

#Defines active object name.
active_object_name = bpy.context.active_object.name

meshKey = bpy.data.meshes[active_object_name].shape_keys
valDrive = meshKey.key_blocks[selected_shape_key_name]

print(valDrive.driver.type.targets[0].bone_target)
You can access it at shape_keys.animation_data.drivers.
import bpy

shape_key = bpy.context.object.active_shape_key
if shape_key is None:
    raise()

shape_keys = shape_key.id_data
if shape_keys.animation_data is None:
    raise()

for fc in shape_keys.animation_data.drivers:
    print(fc.data_path)
    print(fc.driver.type)

Hierarchy

Direct access
&gt;&gt;&gt; 
&gt;&gt;&gt; def fn(name):
...     if name == &quot;&quot;:
...         print(False)
...     else:
...         print(name)
... 
&gt;&gt;&gt; fn(bpy.data.shape_keys['Key'].animation_data.drivers[0].driver.variables[0].targets[0].bone_target)
False

&gt;&gt;&gt; bpy.data.shape_keys['Key'].animation_data.drivers[0].driver.variables[0].targets[0].bone_target = &quot;Bone.001&quot;
&gt;&gt;&gt; 
&gt;&gt;&gt; fn(bpy.data.shape_keys['Key'].animation_data.drivers[0].driver.variables[0].targets[0].bone_target)
Bone.001