How can I change the color of a material using Python script?
This is related: Control Cycles material nodes and material properties in Python

This is how you add an keyframe:

import bpy
# get the material
mat = bpy.data.materials['Material_Name']
# get the nodes
nodes = mat.node_tree.nodes
# get some specific node:
# returns None if the node does not exist
emission = nodes.get("Emission")
# set strength to 0.8
emission.inputs[1].default_value = 0.8
# add keyframe to strength at frame 1
emission.inputs[1].keyframe_insert("default_value", frame=1)
# set strength to 0
emission.inputs[1].default_value = 0
# add keyframe to strength at frame 21
emission.inputs[1].keyframe_insert("default_value", frame=21)


Now the intensity will animate from 0.8 to 0 in 20 frames