Normalize / Create a unit quaternion number / calculation using Python and Blender
This can be done making and using the function below:

Original:

def normalize(v, tolerance=0.00001):
    mag2 = sum(n * n for n in v)
    if abs(mag2 - 1.0) &gt; tolerance:
        mag = math.sqrt(mag2)
        v = tuple(n / mag for n in v)
    return np.array(v)


Updated Version using batFINGER suggestion: April 26 2020

def normalize(v, tolerance=0.00001):
    mag2 = sum(n * n for n in v)
    if mag2 &gt; tolerance:
        mag = math.sqrt(mag2)
        v = tuple(n / mag for n in v)
    return np.array(v)


Or using the built in Function

import mathutils
quat1 = mathutils.Quaternion((1, 2, 3, 4))
quat1_norm = quat1.normalized()
print(quat1_norm)