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 by clicking the <kbd>arrow icon</kbd> in the screenshot, then clicking the option <kbd>Navigate</kbd> to toggle visibility for the gizmo.

There is also the shortcut <kbd>CTRL + ~</kbd> to toggle the gizmo visibility.

[![enter image description here][1]][1]


  [1]: https://i.sstatic.net/8wApc.jpg