Using keyframe_insert
automatically sets the curve handle type to 'BEZIER' as mentioned here.
Assuming you do use you're posted script:
import bpy
obj = bpy.context.object
# set the keyframe at frame 1
obj.rotation_euler = (0, 0, 0)
obj.keyframe_insert(data_path="rotation_euler",index= 1, frame=1)
# set the keyframe at frame 24
obj.rotation_euler = (0, 6.28, 0)
obj.keyframe_insert(data_path="rotation_euler",index= 1, frame=24)
There is no longer a direct reference to the action or key just created so lets find it.
# ensure the action is still available
if obj.animation_data.action:
# and store it in a convenience variable
my_action = bpy.data.actions.get(obj.animation_data.action.name)
Now we want to specifically find the fcurve related to the data_path used above
my_fcu = my_action.fcurves.find("rotation_euler", index=1)
And finally we can set the interpolation of the handles
# for all points
for pt in my_fcu.keyframe_points:
pt.interpolation = 'CONSTANT'
# for a specific frame
frm = 24
pt = [pt for pt in my_fcu.keyframe_points if pt.co[0] == frm][0]
pt.interpolation = 'CONSTANT'