mercredi 1 juin 2022

Dynamically calling decorated functions in sequence [duplicate]

I want to expose an api endpoint that allows a user to submit a payload w/ a sequence of functions to be called (pre-defined), along with their parameters.

Also, these functions are wrapped with decorators.

What is the proper way of accessing a function by name in python?

example payload:

{
    "step1": {
        "fn": "function_1",
        "params": {
            "input_file": "example.txt"
        }
    },
    "step2": {
        "fn": "function_2",
        "params": {
            "y": 2
        }
    }
}

In this scenario I should have python run function_2(function_1("example.txt")``, kwargs=**step2["params"])





Aucun commentaire:

Enregistrer un commentaire