'Trigger a DAG Run from a python

I wrote a python program to create a DAG file. After creating this DAG file, I want to trigger this DAG run. I tried to use the following code -

from airflow.api.client.local_client import Client

c = Client(None, None)
c.trigger_dag(dag_id='local_job_md', run_id='local_job_md', conf={})

But this code is getting error as it is not able to find DAG table in sqlite. After little research, I realized this might be an issue for some gaps in installation. I am new to API but I realized that there is a way to use stable Rest API to trigger the DAG from my program. I need help in this from you people. I want to trigger the DAG from my code badly.

Please help me out from such a situation. Any help is appreciated!

Thanks,

Jay



Solution 1:[1]

Even though you only want to use the API, you still need to initialize the Airflow DB. Unable to find the dag table in sqlite means you don't have your airflow.db initialized.

To do this, go to your $AIRFLOW_HOME directory and run:

airflow initdb

If this command doesn't work for you, you may not have set up Airflow correctly, so I'd suggest starting with the install steps from the beginning.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Thom Bedford