How to keyframe vertices in phython?

I want to key frame all the vertices of a mesh within a python script. I cant work out how to do it. I have tried calling the insertKeyframe() function of the mesh object but this doesnt work. Any help would be much appreciated.

I would just make a shape key and keyframe that.

How would I do that? I have looked into shape keys but can’t work out how to use them properly within a script.

I’m now able to insert keys into my mesh using mesh.insertKeyFrame(), but I want to know how to assign this new key to a frame. According to the api, I can pass a frame number to the insertKeyFrame() function, but this doesn’t seem to change anything.

Al I want to do in my script is edit the mesh shape for each frame, and set a mesh key for that frame. I’m sure this shouldn’t be hard, but I can’t get an easy answer.