Shruti Hande
10/18/2022, 5:58 AMSanthosh Solomon (Fluffy)
10/18/2022, 10:28 AMJeff Hale
10/18/2022, 1:45 PMpip install prefect-shell
to install the prefect-shell collection. Then you can do something like this:
from prefect import flow, task
from prefect_shell import shell_run_command
@flow
def example_shell_run_command_flow():
return shell_run_command(
command="touch new_file.py; ls",
return_all=True,
)
print(example_shell_run_command_flow())
shell_run_command
creates a prefect task.
You can call each Python script consecutively in a single flow OR create a flow for each Python script (subflows).
Hereβs an example that uses subflows - you would just call your script where I create and list files:
from prefect import flow, task
from prefect_shell import shell_run_command
@flow
def first_shell_command():
return shell_run_command(command="touch new_file1.py; ls ", return_all=True)
@flow
def second_shell_command():
return shell_run_command(command="touch new_file2.py; ls", return_all=True)
@flow
def example_shell_run_command_flow():
file1 = first_shell_command()
file2 = second_shell_command()
return file1 + file2
print(example_shell_run_command_flow())
Just note that because shell_run_command
returns a task, you canβt use it within a task.Khuyen Tran
10/18/2022, 3:27 PMShruti Hande
10/19/2022, 7:13 AM