https://prefect.io logo
Title
g

Giacomo Chiarella

05/23/2023, 1:08 PM
Hi everyone! How can I create a variable (this one) using python package prefect 2.10.10?
f

flapili

05/23/2023, 1:09 PM
you probably can use client
from prefect import get_client
IIRC
g

Giacomo Chiarella

05/23/2023, 1:10 PM
ah right, totally forgot, thanks!
@flapili unfortunately there is no api to create a variable using the client
there are only read methods
f

flapili

05/23/2023, 1:15 PM
then grab httpx session from client and do a http requests
it's a little ugly but it should work
g

Giacomo Chiarella

05/23/2023, 1:16 PM
never done that, do you have a snippet of code as example?
f

flapili

05/23/2023, 1:16 PM
instead client will come from an attribut of the prefect client
g

Giacomo Chiarella

05/23/2023, 1:17 PM
should I use async from inside a task?
f

flapili

05/23/2023, 1:18 PM
probably
I believe prefect client use a httpx async session
aren't you sure you won't need block instead ?
variable is for var templating of projects primary if I understood correctly
g

Giacomo Chiarella

05/23/2023, 1:20 PM
yes, I just want to save a flow parameter (like start date), to be able to make the flow extracting data from the value stores in the variable
or maybe a json with a couple of parameters
f

flapili

05/23/2023, 1:20 PM
then use a json block ?
g

Giacomo Chiarella

05/23/2023, 1:21 PM
lol I didn’t know the existence of that, maybe that is better
the conversion would be free
then what are variables for?
f

flapili

05/23/2023, 1:25 PM
to me (but I maybe missunderstood) it's usefull to bootstrap prefets's projects
g

Giacomo Chiarella

05/23/2023, 1:26 PM
generally speaking then I would use variable to save global configuration, I mean a parameter that should have the same value for every flow