Hide panels with python
Currently the Python API can't handle opening and closing panels (it's not exposed).

Related: Is it possible to expand/collapes all panels in a region with a keystroke or shortcut?

The only thing you can do with python is to toggle by calling operators:

bpy.ops.view3d.properties()
bpy.ops.view3d.toolshelf()


They need the right context though, so they need to be called from the 3dview area or the context needs to be overwritten. This will toggle all panels in all 3d_views inside window:

for area in bpy.context.screen.areas:
    if area.type == 'VIEW_3D':
        context_copy = bpy.context.copy()
        context_copy['area'] = area
        bpy.ops.view3d.properties(context_copy)
        bpy.ops.view3d.toolshelf(context_copy)