Thread
#prefect-server
    Aleksandr Glushko

    Aleksandr Glushko

    10 months ago
    Hi all! Could anyone explain please, if I register flow with some parameters, for example: a=10. And in the flow i have:
    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:
    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
    Anna Geller

    Anna Geller

    10 months ago
    here is an example:
    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()
    Aleksandr Glushko

    Aleksandr Glushko

    10 months ago
    So to retrieve the parameter, it should be run in the task?
    Anna Geller

    Anna Geller

    10 months ago
    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
    Aleksandr Glushko

    Aleksandr Glushko

    10 months ago
    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!