How can I create a cylinder linking two points with Python? I want to position a cylinder such that the center of one end is at (x0, y0, z0) and the center of the other end is at (x1, y1, z1) using the Python API.

The intention is that there will be two spheres centered at those coordinates and the cylinder will act as a spoke or connector between them.

I guess I will create the cylinder then translate, scale, rotate it. I am struggling mainly with the rotate part.
i wrote my own script, as there is no way to do it with blender API direcly:

def cylinder_between(x1, y1, z1, x2, y2, z2, r):

  dx = x2 - x1
  dy = y2 - y1
  dz = z2 - z1    
  dist = math.sqrt(dx**2 + dy**2 + dz**2)

  bpy.ops.mesh.primitive_cylinder_add(
      radius = r, 
      depth = dist,
      location = (dx/2 + x1, dy/2 + y1, dz/2 + z1)   
  ) 

  phi = math.atan2(dy, dx) 
  theta = math.acos(dz/dist) 

  bpy.context.object.rotation_euler[1] = theta 
  bpy.context.object.rotation_euler[2] = phi 


enjoy :-)