how to adapt a box to an object with a python script?
I found how to move the highest plan of the bounding box and position it correctly above the object : 

activeob = bpy.context.selected_objects
cube = activeob[0]
bpy.context.scene.objects.active = bpy.data.objects[cube.name]
bpy.ops.object.mode_set(mode='EDIT')
mesh = bmesh.from_edit_mesh(cube.data)  
ob = bpy.data.objects[cube.name]
matrix = ob.matrix_world
for v in mesh.verts:
    if v.select:
        v.co = v.co*matrix
        v.co.z += 20
        matrix_inv = matrix.inverted()
        v.co = matrix_inv*v.co