How do I add a constraint to an object with Python?
import bpy

o = bpy.context.object
constraint = o.constraints.new('COPY_LOCATION')

#constraint properties
constraint.show_expanded = False
constraint.mute = True


https://www.blender.org/api/blender_python_api_2_77_release/bpy.types.ObjectConstraints.html?highlight=constraints#bpy.types.ObjectConstraints

https://www.blender.org/api/blender_python_api_2_77_release/bpy.types.CopyLocationConstraint.html?highlight=constraints