<@U06RKAMK0UC> how can I use argparse with pyflyte...
# ask-ai
g
@ancient-wolf-19325 how can I use argparse with pyflyte script
j
To use
argparse
with a
pyflyte
script, you need to modify your script to handle command-line arguments. However, it's recommended to use
pyflyte run
for running workflows as it simplifies the process. Here's how you can do it: 1. Modify your script to use
argparse
: Add an
argparse
block to handle command-line arguments. 2. Run the script using
pyflyte run
: Use
pyflyte run
to execute the script with the specified arguments. Example:
Copy code
import argparse
from flytekit import task, workflow

@task
def my_task(name: str) -> str:
    return f"Hello, {name}!"

@workflow
def my_workflow(name: str) -> str:
    return my_task(name=name)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Run Flyte workflow")
    parser.add_argument("--name", type=str, required=True, help="Name to greet")
    args = parser.parse_args()
    print(my_workflow(name=args.name))
Run the script with `pyflyte run`:
Copy code
pyflyte run my_script.py my_workflow --name "Flyte"
Would you like more detail? Sources: - Running a workflow locally 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.
f
I have a PR out to run simple scripts
We will be merging this soon