Animate curves by changing spline data using a python script I generated a curve using the following python code

curve = bpy.data.curves.new("Curve", type='CURVE')
polyline = curve.splines.new(type='POLY')
polyline.points.add(n - 1) # The polyline has one point when created
polyline.points.foreach_set('co', data) # data is the array of coordinates


This works perfectly in generating the data I want. And now I want to create an animation for this curve by using pre-calculated data stored in a file.

Thus I am trying to use in a different script the following:

curve= bpy.data.objects["Curve"]
# for i ...
    # get new data
    curve.data.splines.foreach_set("location", data)
    curve.keyframe_insert(data_path="location", frame=i)


I tried different variations of the above segment to find a way to get to the points in the splines but no attributes exist for that.

Any suggestions?
Apparently the answer is simple to this, I had to choose splines[0]

curve = bpy.data.objects["Curve"]
points = cable.data.splines[0].points
# for i ...
    # get new data
    points.foreach_set("co", data)
    for point in points:
        point.keyframe_insert(data_path="co", frame = i)