Blender 2.9 scripting, how to get the name of the driven property

I'm trying to get the name of the property that's been affected by a driver for a certain object, what I did so far:

for d in bpy.context.object.animation_data.drivers:
print(d.driver.id_data.name)


However, that's returning the name of the object, not the driven property.
My question is, let's say there's a drive controlling the Z Scale, how do I get that information "Z Scale" or a similar equivalent, in scripting?

• – batFINGER Oct 26 at 11:45
• Thank you @batFINGER very helpful, as always – Georges Oct 26 at 11:47
• Cheers. Initially closed as a dupe, ... changed mind after looking at answer script which will do nought if there are no variables, which is often the case with use_self or when using frame or other vars known to namespace. Closing is no big deal tho, more in re to linking alike questions. – batFINGER Oct 26 at 12:01
• Totally agree, I believe answers to both questions are helpful – Georges Oct 26 at 12:08

Use f_curve.data_pathand f_curve.array_index to get the property index in case of vectorized properties (like location, scale, etc.)

import bpy

if bpy.context.active_object and bpy.context.active_object.animation_data:
for d in bpy.context.active_object.animation_data.drivers:
print(bpy.context.active_object)
print(f"Driven property : {d.data_path}")
print(f"Property index : {d.array_index}")


Example :

• Great answer, thank you – Georges Oct 26 at 11:40