https://prefect.io logo
v

Verun Rahimtoola

02/10/2021, 7:40 PM
hi, if i have a task that can take in a very large number of parameters, is it possible to pass them all in as a collection to the task? eg:
Copy code
with Flow(...) as f:
   param_1 = ...
   param_2 = ...
   ...
   param_n = ...
   x = my_task([param_1, param_2, ..., param_n])
z

Zanie

02/10/2021, 7:44 PM
Looks like it 🙂
Copy code
In [2]: from prefect import Flow, task, Parameter

In [3]: @task
   ...: def foo(params):
   ...:     print(params)
   ...: 

In [4]: with Flow("foo") as flow:
   ...:     x = Parameter("x", default=1)
   ...:     y = Parameter("y", default=2)
   ...:     foo([x, y])
   ...: 

In [5]: flow.run()
[2021-02-10 13:44:22-0600] INFO - prefect.FlowRunner | Beginning Flow run for 'foo'
[2021-02-10 13:44:22-0600] INFO - prefect.TaskRunner | Task 'y': Starting task run...
[2021-02-10 13:44:22-0600] INFO - prefect.TaskRunner | Task 'y': Finished task run for task with final state: 'Success'
[2021-02-10 13:44:22-0600] INFO - prefect.TaskRunner | Task 'x': Starting task run...
[2021-02-10 13:44:22-0600] INFO - prefect.TaskRunner | Task 'x': Finished task run for task with final state: 'Success'
[2021-02-10 13:44:22-0600] INFO - prefect.TaskRunner | Task 'List': Starting task run...
[2021-02-10 13:44:22-0600] INFO - prefect.TaskRunner | Task 'List': Finished task run for task with final state: 'Success'
[2021-02-10 13:44:22-0600] INFO - prefect.TaskRunner | Task 'foo': Starting task run...
[1, 2]
[2021-02-10 13:44:22-0600] INFO - prefect.TaskRunner | Task 'foo': Finished task run for task with final state: 'Success'
[2021-02-10 13:44:22-0600] INFO - prefect.FlowRunner | Flow run SUCCESS: all reference tasks succeeded
Out[5]: <Success: "All reference tasks succeeded.">
v

Verun Rahimtoola

02/10/2021, 7:45 PM
awesome, thanks @Zanie!
z

Zanie

02/10/2021, 7:45 PM
They are automatically wrapped in a
List
task
v

Verun Rahimtoola

02/10/2021, 7:45 PM
excellent, just what i needed!
3 Views