Use "Add 3D Function Surface" addon via python
All of blender's plugins are python scripts, so I looked up the script and was going through it's code when I realized that was a really bad idea.  If you grab the bottom of the top menu bar and pull down it gives you a list of all the commands blender has recently executed. Add a couple surfaces, and voila, it looks like these commands should be a good start to what you want:

bpy.ops.mesh.primitive_z_function_surface(div_x=20, div_y=17)
bpy.ops.mesh.primitive_xyz_function_surface(x_eq="cos(v)*(1+cos(u))*sin(v/3)", z_eq="sin(v)*(1.3+cos(u))*sin(v/8)")


They can be used in a script (blender's user interface uses python, so everything that shows up in the command list is valid python), just don't forget to import bpy.