Python controle Constrain to Image Bounds
Look in info area

In this case if we open an info window and toggle the setting in the image editor



We see the property is lock_bounds of the uv_editor settings of the image editor space.
Python console code to get there, in same screen. Beware: currently trying to auto complete an image editor  space from another (other than context) screen core dumps my 2.8 build

&gt;&gt;&gt; for i, a in enumerate(C.screen.areas):
...     i, a.type
...     
(0, 'PROPERTIES')
(1, 'CONSOLE')
(2, 'OUTLINER')
(3, 'VIEW_3D')
(4, 'IMAGE_EDITOR')
(5, 'INFO')

&gt;&gt;&gt; a  = C.screen.areas[4]
&gt;&gt;&gt; s = a.spaces.active
&gt;&gt;&gt; s
bpy.data.screens['Scripting.001']...SpaceImageEditor

&gt;&gt;&gt; s.uv_editor.lock_bounds = True
&gt;&gt;&gt;


Although can set without, for the menu to show, mesh object needs a UV map and be in edit mode.