Add rotation to a key frame
scn = bpy.context.scene
wd = scn.world
envnt = bpy.data.worlds[wd.name].node_tree
map_node = envnt.nodes['Mapping']
map_node.inputs['Rotation'].default_value.x = &lt;x value of rotation&gt;
map_node.inputs['Rotation'].default_value.y = &lt;y value of rotation&gt;
map_node.inputs['Rotation'].default_value.z = &lt;z value of rotation&gt;
map_node.inputs['Rotation'].keyframe_insert(&quot;default_value&quot;, frame=&lt;frame number&gt;)