Local collections hide/show with Python script

Hi! I’m working on a script that add a new Workspace with a 3D View and I want to hide some collections only in that viewport.

I’ve seen that there is this property:

bpy.context.space_data.use_local_collections = True

but I don’t understand how to access these properties from Python API:

enter image description here

I know there is an operator:

bpy.ops.object.hide_collection()

but it would be better a low level access instead.
The only workaround I found is this: Modify the visibility of collections locally to the viewport with python but:

  1. it’s quite old topic, I hope for a non-op solution
  2. I’m not able to make it work (with op) because I have a context error an I don’t understand how to solve it

Any idea how to make this work without using an operator or if the operator is the only way, how to make it work?

Thank you

Thank you for your reply, unfortunately it does not fit my needs.
As I wrote, I need to hide a collection in a specific 3d view and not globally.
I need also to do that in a different context.

LayerCollections are tied to the view layer and outliner states- so without the UI already being in that ‘state’ (eg: you are in the specific view and context you need) you cannot modify them because they don’t exist yet.

argh, I was afraid of something like this… although actually I’m trying to work around it by using the context override.
However with the new temp_override method I can’t set the correct screen, while with the old deprecated method I can act on the collections for a specific view but… I have to call another operator which is executed only at the end of my script and I don’t understand why.
This operator actually shuts down the collections in the correct view but it seems to get the collection index completely wrong…