OpenCV has this. See this:
http://docs.opencv.org/trunk/dd/d49/tutorial_py_contour_features.html
7.b. Rotated Rectangle
With
cv2.minAreaRect(cnt)
You can get the length and width of the rectangle as well as its angle. You can also compute the corners if you wish to draw it.