There may be an way to do it with BPY code that I am unaware of.
On the other hand, you can toggle the viewport 3D gizmo visibility by clicking the arrow iconViewport Gizmos popover menu in the screenshot3D View header, then clicking the option NavigateNavigate.
There is also the shortcut CTRL + ~ to toggle the gizmo visibility.