Hi all, I want to try the new `variables` function...
# ask-community
s
Hi all, I want to try the new
variables
functionality in Prefect 2.10.4, and I have a (stupid?) question…. How do you set them from inside a task of flow with Python? I can’t find any reference to setting variables, only retrieving them, and the only ways to set them seem to be through the UI or the REST API. Is this correct? Or am I missing something obvious?
1
f
Hi, I think you can use the prefect http client 😉
j
Hi @Simon Rascovsky, I'm Prefect's head of product. Currently, there is no
varaibles.set()
method in the Prefect CLI. I'm curious, if we added it, what would you use it for?
s
I have a task that periodically checks a changes feed from an API, and I wanted to store the pointer of the last record queried from that API so the next check starts from that record on, and I thought perhaps storing it in a variable would be a simple solution instead of creating my own table to persist this pointer. Not sure if that’s a reasonable intended use of the variables concept, though?
j
That makes sense, thank you. In that case you'd be using variables more like a key value store, which we would recommend a string block for. That said - you are not the first person to want to use variables this way - we may add the ability to set them from the SDK. I'll keep you posted as our thinking evolves on that.
👍 1
s
Thank you!
s
I have the same use case - It sounded like
variables
was the feature to replace string Blocks with, but since I can’t set a variable from within a task or flow, then I need to stick with string Blocks
g
I agree - it seemed to me like variables was a good lightweight alternative to string blocks. I would find that useful