Of course, there’s the UE documentation related to using Pyton in the engine, that can be found here:
And as an example, another scenario that aimed to add new nodes to an event graph using Python can be checked here:
As for the code itself for your case, you would need to inquire with a python user, or, though I don’t personally recommend it, check with an IA, to setup the solution.