This snippet calculates an aspect ratio of a rectangle not constrained to be parallel to the coordinate axes:
from shapely import *
rect = oriented_envelope(LineString([(1, 1), (5, 1), (10, 10)]))
p0 = get_point(rect.exterior, 0)
p1 = get_point(rect.exterior, 1)
p2 = get_point(rect.exterior, 2)
d0 = distance(p0, p1)
d1 = distance(p1, p2)
aspect = min(d0, d1)/max(d0, d1)
print(f'{rect:.1f} {aspect:.2f}')
Output:
POLYGON ((3.0 -1.0, 12.0 8.0, 10.0 10.0, 1.0 1.0, 3.0 -1.0)) 0.22
Is there a simpler way to accomplish it?