Hi Kedro Team I'm using Kedro `0.16.6` and using ...
# questions
a
Hi Kedro Team I'm using Kedro
0.16.6
and using the
load_context
to get
params
,
"credentials*", "credentials*/**"
. We're upgrading
Kedro
to
0.18.8
and it seems
load_context
is no more accessible. How can I replicate the same functionality in the Kedro 0.18.8?
m
Implement a hook
after_context_created
j
I ment ahead and looked at the various migrations guides at https://github.com/kedro-org/kedro/blob/main/RELEASE.md, and I don't see much practical advice. I'll be opening an issue, because I think having better guidelines there might benefit lots of users
for future reference, the removed function was
kedro.context.load_context
I believe 👍🏼 which was later moved to
kedro.framework.context.load_context
and then removed in 0.18.0
the alternative is the
KedroSession.load_context
method @Afaque Ahmad. as @marrrcin says, you can hook into the
after_context_created
, which gets passed an instance of the
KedroContext
. for more information on how to use Hooks, see https://docs.kedro.org/en/stable/hooks/introduction.html
and if you have any question about this, please ask!
a
Thanks very much for the inputs @Juan Luis, @marrrcin My use case is to retrieve values stored in
parameters
and
credentials
in a script, so
after_context_created
may not be what I'm looking for. I'll try to create a
KedroSession
and access
load_context
from there to get the
parameters
and
credentials
.
j
I'm not sure creating a new
KedroSession
will give you what you need, but I could be wrong. how are you using the script? is it something you call as part of a node?
a
The script is basically used to fetch parameters and credentials for initialising an
MLFlowClient
. This is one example, its being used for many other purposes also. An example below:
Copy code
project_root = _def_get_parent_dir()

# Load kedro context in order to reuse parameters
context = load_context(project_root)

tracking_uri = context.params.get("mlflow_tracking_uri")
registry_uri = context.params.get("mlflow_registry_uri")

credentials = context.config_loader.get("credentials*", "credentials*/**")
mlflow_creds = credentials.get("mlflow")

client = MlflowClient(tracking_uri=tracking_uri, registry_uri=registry_uri)
👍🏼 1
j
I see - in this case, it might indeed make sense to create your own
KedroSession
m
Why aren’t you using
kedro-mlflow
? It’s a great, production tested plugin @Afaque Ahmad
y
Even if you don't want to use
kedro-mlflow
(which does something very similar to what you are trying to achieve), it is worth checking the code to see how this is handled: The idea is to store what you need through a hook https://github.com/Galileo-Galilei/kedro-mlflow/blob/845ad919c9dbd020e948e8adc2e0f9064de1ef68/kedro_mlflow/framework/hooks/mlflow_hook.py#L38 and then retrieve through
session.context
attribute. Check this line to see how the context is modified by the hook and theses discussions (1, 2, 3) to understand why and how things were modified along kedro versions updates. If you have the
kedro-mlflow
plugin installed, you can access the client through
context.mlflow.server._mlflow_client
.
a
This is super helpful, I'll refer to this while doing the migration and get back again if I have questions. Thanks again @Yolan Honoré-Rougé @Juan Luis @marrrcin
👍🏼 1
đź‘Ť 1