Python - Linear interpolation before keyframe
Just to follow up with the help from @batFINGER:
import bpy

o = bpy.context.selected_objects[0]

for fc in o.animation_data.action.fcurves:
    fc.extrapolation = 'LINEAR'