https://prefect.io logo
#prefect-server
Title
# prefect-server
a

Aleksandr Glushko

11/24/2021, 4:34 PM
Hi all! Could anyone explain please, if I register flow with some parameters, for example: a=10. And in the flow i have:
Copy code
with Flow('flow_name') as flow:
  a = prefect.Parameter('a', 'required'=True)
  <http://logger.info|logger.info>(a)
how can i get the parameter value to be used? So i want
a
to be 1, but I get:
a = <Parameter: a>
Im running the flow in the following way:
Copy code
prefect_client.graphql(query= """
                                mutation{
                                    create_flow_run(input: { flow_id: %s , parameters: %s}) {
                                    id
                                    }
                                }
                                """ % (train_flow_id, json.dumps(flow_params).replace('"', '\"'))
                                )
where flow_params is a dictionary
a

Anna Geller

11/24/2021, 4:36 PM
here is an example:
Copy code
from prefect import task, Flow, Parameter


@task(log_stdout=True)
def hello_world(name):
    print(f"hello {name}")


with Flow("mini.example") as flow:
    name = Parameter("name", default="Aleksandr")
    hw = hello_world(name)

if __name__ == "__main__":
    flow.run()
a

Aleksandr Glushko

11/24/2021, 4:38 PM
So to retrieve the parameter, it should be run in the task?
a

Anna Geller

11/24/2021, 4:39 PM
you can pass the value to another task as data dependency, correct. Have a look at this documentation page: https://docs.prefect.io/core/concepts/parameters.html
a

Aleksandr Glushko

11/24/2021, 4:41 PM
Thank you, have seen it, was thinking if there is a method to retrieve a parameter without another task, for e.g. having a parameter class method: param.get_value(). But i get it, thank you!
🙌 1
2 Views