Search code examples
pythonkedro

Setting parameters in Kedro Notebook


Is it possible to overwrite properties taken from the parameters.yaml file within a Kedro notebook?

I am trying to dynamically change parameter values within a notebook. I would like to be able to give users the ability to run a standard pipeline but with customizable parameters. I don't want to change the YAML file, I just want to change the parameter for the life of the notebook.

I have tried editing the params within the context but this has no affect.

context.params.update({"test_param": 2})

Am I missing something or is this not an intended use case?


Solution

  • Kedro supports specifying extra parameters from the command line by running

    kedro run --params "key1:value1,key2:value2"
    

    which solves your second use case.

    As for the notebook use case, updating context.params does not have any effect since the context does not store the parameters on self but rather pulls them from the config every time the property is being called.

    However you can still add extra parameters to the context object after it being instantiated:

    extra_params = context._extra_params or {}
    extra_params.update({"test_param": 2})
    context._extra_params = extra_params
    

    This will update extra parameters that are applied on top of regular parameters coming from the config.