Align to vector in viewport

Aloha everyone, I use this code in the BGE to align an objects -z with a vector. Is there a way to do this in the viewport prior to run time? Does bpy have this function, or something similar, as well?


def zalign():
    
    scene = logic.getCurrentScene()
    cont = logic.getCurrentController()
    own = cont.owner
    
    for obj in scene.objects:
        if "zalign" in obj:
            up_vec = own.getVectTo(obj)[1]
            obj.alignAxisToVect(up_vec, 2, 1)

You can setup your camera and have it aligned along the correct axis then have your view configured from that camera’s point of view.