How to lock viewport to object via the Python API
Property of the 3D view space
Similarly to Change tile grid shape and similarly to the answer it was similar to.
Mousing over the property in UI (with developer extras enabled) shows the proprerty as
SpaceView3D.lock_object 

Python console, lock 3d viewport area of screen to context object.
&gt;&gt;&gt; for i, a in  enumerate(C.screen.areas):
...     i, a.type
...     
(0, 'PROPERTIES')
(1, 'CONSOLE')
(2, 'OUTLINER')
(3, 'VIEW_3D')

&gt;&gt;&gt; space = C.screen.areas[3].spaces.active



&gt;&gt;&gt; space.lock_object = C.object
&gt;&gt;&gt; C.object
bpy.data.objects['Cube']

&gt;&gt;&gt; space.lock_object
bpy.data.objects['Cube']

&gt;&gt;&gt; type(space)
&lt;class 'bpy.types.SpaceView3D'&gt;

set to None to remove
space.lock_object = None

For scripts run in the context of the 3d view
space = context.space_data