Hitting the animation button thrue your python scrip is really easy ...
import bpy
bpy.ops.render.render(animation = True)
But this leaves your script completely out of the loop
What if you want to change things in your animation
with your script, without the hastle of scripting in key-frames....
key frames are often convenient for humans but not for humans writing scripts lol
Here is a scrip that renders on frame of your animation at a time and advances to the next frame
all on its own .. your scrip is back in the animation loop.
import bpy # python imports a library of commands used to control blender
# LIST OF VARIABLES / PARAMATERS
Start = 1 # Frame the animation will start on
End = 20 #Frame the animation will end on
# MAIN PART OF SCRIP BEGINS
for i in range(Start, End): # i will grow from Start to End by one each time the indented text below is caried out
bpy.data.scenes[0].render.filepath= ('C:\\Users\\rylangrayston\\Desktop\\bpyoutput\\' + str(i) + 'a.jpg') # this sets the path and file name where each file is saved + str(i) + adds in the string equivilant of the intager i
bpy.data.scenes[0].frame_set(i) # this sets the animations frame to the falue held by the variable i
bpy.ops.render.render(write_still=True) # This renders the current frame
#Here you can add code that changes your animaion each frame
#If you have put key frames into blender buy hand they will show in the animation
Code works in Blender 2.63
Be sure to change the file path on line 10 to something that works one your computer