How to set keyframe handles to be interpolated via script on the fly (low-level variant: keyframe_points.add(int) + keyframe_points[i].co=..)?
When using keyframe_insert() the default interpolation set in preferences is applied to each keyframe as it is added, this doesn't happen when using fcurves.new(), which always leaves it at bezier. If you don't want to use bezier interpolation then you will need to set the interpolation for each point as you create them.

fcu_x.keyframe_points[i].interpolation = 'LINEAR'


Then you will want to call fcurve.update().


  update()
  Ensure keyframes are sorted in chronological order and handles are set correctly