How to hide/show Collections levels with python?

Hello in this code below i create a lot of collection and add backups inside of them, its kind of a cool within the file backup system i wrote for my new save management add-on

import bpy 
import os
import datetime

context = bpy.context
scene = context.scene
A = context.object
S = bpy.context.selected_objects

#Date name and .blend name 
time =
date= time.strftime("__%Y-%m-%d_%HH%MM%S")
datecol= time.strftime("%m-%d_%HH%MM%S")
blend = bpy.path.basename([:-6]

#Collection Copies
def find_collection(context, item):
    collections = item.users_collection
    if len(collections) > 0:
        return collections[0]
    return context.scene.collection

def make_collection(collection_name, parent_collection):
    if collection_name in
        new_collection =
        return new_collection
name = "Copies"

#Collection Date
def make_collection(collection_namme, parent_collection):
    if collection_namme in
        new_collection =
        return new_collection
namme = datecol

#Dupplicate selection and move it to scene master collection
bpy.ops.object.duplicate_move(OBJECT_OT_duplicate={"linked":False, "mode":'TRANSLATION'})

#move every object to new collection
for C in bpy.context.selected_objects: = + " Copy"

    C_collection = find_collection(bpy.context, C)
    new_collection = make_collection(name , C_collection)
    C_collection.objects.unlink(C)["Copies"].hide_select = True["Copies"].hide_render = True["Copies"].hide_viewport = True
    C_collection = find_collection(bpy.context, C)
    new_collection = make_collection(namme , C_collection)
    C_collection.objects.unlink(C)[datecol].hide_select = True[datecol].hide_render = True[datecol].hide_viewport = True = A
for ob in S:

the only problem is that it create a lot of collection and i can’t “close” them, they stay enter and take all the space in the outliner, i just want to automate this


the code seems to be eclusive to context.outliner, i can’t even find it
do anyone know how to do this ? is there some examples anywhere ?

the operator is bpy.ops.outliner.show_one_level( open=True )
but I couldn’t find the command in the maybe it does not have a python wrapper for it.
I did found the operator in the build,but since I know little of C I can’t make out if it uses a function that has a python function.