get newly created keyframe in python I would like to get a reference to a keyframe when I create it. Alas, keyframe_insert() returns a bool indicating success, not a handle to the keyframe.

In my application, each keyframe may need a different interpolation mode (or other parameter) so it seems good to do this at creation time.  Consider doing the following for an object where dataset has many elements:

ob = bpy.context.active_object
prop='["MyParam"]'

for interp, value, frame_time in dataset:
    ob['MyParam'] = value
    ob.keyframe_insert(data_path=prop, frame=frame_time)
    # interp = LINEAR or BEZIER or ...
    # set this one appropriately:  How?


The only thing I can see at the moment is seems complicated:


get the fcurves from ob.animation_data.action.fcurves 
ask the fcurves collection to look for the one with the right data_path,
go searching the fcurve for a keyframe with the right values


This seems to look like:

# go looking for it
curve = ob.animation_data.action.fcurves.find(prop)
pts = curve.keyframe_points
# pts.find(key) what is "key" other than "the identifier for the collection member."
# do I need a foreach() loop here?


What would the key parameter be?  Is there a better way?  This multiple-search step seems like it would get costly fast.  Any hints/clues would be welcome.
The find curve by path and insert the keyframe is very common in Blender.

You may not need to find the any keyframe in Blender by key.  You can iterate through them and update a value such as curve type if the frame matches the frame in your inventory by frame number.

If you have potentially extra items you can remove(delete) the entire curve. 

Your concern about time efficiency ("costly") is good yet now may not be the time to optimize.

There is the [add] method documented here.

https://docs.blender.org/api/current/bpy.types.FCurveKeyframePoints.html#bpy.types.FCurveKeyframePoints