Simple script to rotate viewport

I am currently creating a gui for a blender project I am working on and I want to have a rotate viewport linked to a keypress, something similar to 4 and 6 except that the focus does not have to be moved to the viewport and then back to the gui. I have had a look at setViewOffset and setViewQuat but before I go plunging into a horrible mathematical formula for rotations I was wondering if there is an easier way to get this functionality.
Any help would be greatly appreciated!