How to use Keyframes and the Python API programmatically? Currently I have a default cube and 400 frames.

Here's what I have working without keyframing

import bpy

current_scene = bpy.context.scene

default_cube = current_scene.objects['default_cube']

def update_scene():
    current_frame_value = current_scene.frame_current

    if current_frame_value &lt; 100:
        default_cube.scale.x = .05
    elif current_frame_value &lt; 200:
         default_cube.scale.x = .08
    elif current_frame_value &gt; 300:
        default_cube.scale.x = .3
     else:
        default_cube.scale = 1

bpy.app.handlers.frame_change_pre.append(update_scene)

print('I work!')


The problem I'm having with the non-keyframe method is there isn't any interpolation between the scaling and I intend do this for thousands of frames. What is a good method to use keyframes programmatically to achieve interpolation?

https://docs.blender.org/manual/en/latest/editors/python_console.html Blender 2.8 doesn't reference anywhere.
Figured it out!
Here's how to use the Python API to set it:
# X, Y, and Z location to set
default_cube.location = (0.0, 0.0, 0.0)
# Set the keyframe with that location, and which frame.
default_cube.keyframe_insert(data_path=&quot;location&quot;, frame=1)

# do it again!
default_cube.location = (3.0, 2.0, 1.0)
# setting it for frame 10
default_cube.keyframe_insert(data_path=&quot;location&quot;, frame=10)

Details on .keyframe_insert() can be found in Blender's manual.