Hi Prefect, We’re still in our journey to evaluate...
# prefect-community
f
Hi Prefect, We’re still in our journey to evaluate prefect, one question that comes to mind How do we run a flow that takes input parameters ? I mean without deploying to a agent, simply by running it with the command line
1
n
Hi, I'll comment for being noticed if there are other methods but I'm mainly using argparse to receive my params
n
you could use argparse as mentioned by nicolas above, and you can always use
sys.argv
like:
Copy code
import sys
from prefect import flow, get_run_logger, task

@task
def double(x: int) -> int:
    return x * 2

@flow
def my_flow(my_int: int):
    logger = get_run_logger()
    result = double(my_int)
    <http://logger.info|logger.info>(f"Result: {result}")

if __name__ == '__main__':
    my_int_arg = sys.argv[-1]
    
    my_flow(my_int=my_int_arg)
Copy code
❯ python clitriggeredflow.py 4
15:39:02.542 | INFO    | prefect.engine - Created flow run 'uppish-dormouse' for flow 'my-flow'
15:39:03.568 | INFO    | Flow run 'uppish-dormouse' - Created task run 'double-718afc09-0' for task 'double'
15:39:03.570 | INFO    | Flow run 'uppish-dormouse' - Executing 'double-718afc09-0' immediately...
15:39:03.900 | INFO    | Task run 'double-718afc09-0' - Finished in state Completed()
15:39:03.900 | INFO    | Flow run 'uppish-dormouse' - Result: 8
15:39:03.994 | INFO    | Flow run 'uppish-dormouse' - Finished in state Completed('All states completed.')
f
that’s acceptable as a workaround, but prefect should seriously consider integrating a proper library with named arguments like
Copy code
--foo=bar --foo
Don’t want to seems like asking for too much, but it’s a serious drawback if developers are not able to run their scripts locally with proper input parameters
2
n
@Florian Giroud thanks for the feedback! you're welcome to make feature requests here
m
Well, @Florian Giroud I like using argparse to do just what you say. its the clean way to pass arguments to your application. Philosophically, I dont want to interact with Prefect apis except in this domain of workflow management. We arent writing Prefect code, its just a library for our python code.
upvote 2