Trying to set a Keyframe in the Curve Data tab using Python

I've been attempting to set a keyframe for the Bevel Factor Start and End of a Curve.

I've tried using

bpy.ops.anim.keyframe_insert_button(
'Curve.bevel_factor_start',
index=-1,
frame=bpy.context.scene.frame_current,
group="")


But I really don't know where to go from here. Pressing "I" works just fine but I can't find the right command in the API to control this property

• As an addendum to Ratt's answer: By blenders naming convention, if a name starts with a capital it is a class. in this case. bpy.types.Curve A curve objects data part is an instance of type Curve. – batFINGER Jan 31 '19 at 20:18

While likely not optimized the following appears to work both in blender 2.79b official and the 2.80 beta build I have at the moment and may assist in how to handle adding the key frames and manipulating them afterwards.

import bpy

obj = bpy.context.active_object  # Your pre-existing selected curve

if obj.data.bevel_object:  # verify bevel object already selected
obj.data.keyframe_insert(
"bevel_factor_start",
index=-1,
#                frame=1,  # defaults to current frame
#                group=""
)
obj.data.keyframe_insert(
"bevel_factor_end",
index=-1,
#                frame=1,  # defaults to current frame
#                group=""
)

def mod_fcurve(obj, path):
for fc in obj.data.animation_data.action.fcurves:
if fc.data_path == path:
my_fc = fc
for pt in my_fc.keyframe_points:
pt.co.x += 1  # increase x 'frame number' of points
pt.co.y += 0.1  # increase y 'value' of all pts in curve

mod_fcurve(obj, "bevel_factor_start")


Figured it out, this is what I was trying to achieve

bpy.context.object.data.bevel_factor_start = 0 #set factor to 0 bpy.context.object.data.keyframe_insert(data_path='bevel_factor_start') #keyframe it