How to set Inputs for GeometryNodes Modifiers with Code and Debug?

I was trying to create a Drawing Excercise addon for myself with different challenges, so I made a bunch of Geometry Node setups where each one has a Seed input socket that I want to set with code

A modifier looks something like this:

Here is the relevant code snippet:

mod = obj.modifiers.new(name=modf, type='NODES')
mod.node_group = ng

seed = random.randint(0, 1000)
for item in ng.interface.items_tree:
    if item.item_type == "SOCKET" and item.in_out == "INPUT":
        if item.name == "Seed":
            # Set the value on the modifier instance using its identifier
            seed_var = getattr(mod.properties.inputs,item.identifier)
            seed_var.value = seed
            break

This works but it feels hacky since properties supposed to be readonly

I tried to set it with:

mod[item.identifier] = seed

as I see suggested in other posts but I get this error:
kép

I tried looking at the documentation here: NodesModifier
Where it said properties is of type NodesModifierProperties but when I tried to print the type() it said GeometryNodesModifierInterface which I found no documentation for also when I try to access the .values() or .items() I get this error:
kép
Eventhough they are listed in the Inherited Functions section
So I really don’t know how to debug such objects other than dir() the whole thing.
I just wanted to share this to eliviate my frustration whith the horrendous API documentation.

Am I missing something, is there a better way?

that’s not hacky actually, that’s the new way. in 5.x the geo nodes modifier inputs moved to mod.properties.inputs, the old mod[“Socket_2”] = x idea property style is gone, which is why that errors on you

you can skip the loop too:

ident = ng.interface.items_tree["Seed"].identifier
getattr(mod.properties.inputs, ident).value = random.randint(0, 1000)

if you also need it to run on 4.x, check hasattr(mod, “properties”) and fall back to mod[ident] = seed there