Is there any example code available for calling fl...
# prefect-community
r
Is there any example code available for calling flows via some python API (flask / fastapi).
k
Are you using Prefect 1 or 2? You can hit the API for both to trigger flow runs
r
I am using Prefect 1
I am getting
ERROR:prefect.TaskRunner:Unexpected error: OSError(24, 'Too many open files')
error when using Flask API
k
You are trying to use
flow.run()
with an API? I think it will be easier if you trigger a Prefect Cloud Flow Run
r
I am trying to test locally. That's why using that. If I run the flow code as it is, it is working fine. But when ran with flask it is throwing this error. How to trigger prefect cloud flow run?
k
You can use the
Client.create_flow_run
r
Okay will try that. Let me know if there is any work around with running locally
@Anna Geller this is the use case for using client. I am just trying the
get_agent_config
method to test the client. When I use it for triggering the flow it worked.
a
I see - but there is no need to do that - you can use the create_flow_run_task directly in your flow without client and without agent config:
Copy code
from prefect import Flow
from prefect.tasks.prefect import create_flow_run, wait_for_flow_run

PROJECT_NAME = "community"


with Flow("sample_flow") as flow:
    child_run_id = create_flow_run(
        flow_name="child_flow",
        project_name=PROJECT_NAME,
        task_args={"name": "Friendly name for a DAG node"},
    )
    extract_load_wait_task = wait_for_flow_run(
        child_run_id,
        raise_final_state=True,
        stream_logs=True,
        task_args={"name": "Friendly wait task name"},
    )