Package: apache-airflow-client
Apache Airflow Python ClientRequirements.Python >= 3.7Installation & Usagepip installYou can install directly using pip:pipinstallapache-airflow-clientSetuptoolsOr install viaSetuptools.gitclonegit@github.com:apache/airflow-client-python.gitcdairflow-client-python
pythonsetup.pyinstall--user(orsudo python setup.py installto install the package for all users)Then import the package:importairflow_client.clientChangelogSeeCHANGELOG.mdfor keeping
track on what has changed in the client.Getting StartedPlease follow theinstallation procedureand then run the following
example python script:importuuidimportairflow_client.clienttry:# If you have rich installed, you will have nice colored output of the API responsesfromrichimportprintexceptImportError:print("Output will not be colored. Please install rich to get colored output: `pip install rich`")passfromairflow_client.client.apiimportconfig_api,dag_api,dag_run_apifromairflow_client.client.model.dag_runimportDAGRun# The client must use the authentication and authorization parameters# in accordance with the API server security policy.# Examples for each auth method are provided below, use the example that# satisfies your auth use case.## In case of the basic authentication below, make sure that Airflow is# configured also with the basic_auth as backend additionally to regular session backend needed# by the UI. In the `[api]` section of your `airflow.cfg` set:## auth_backend = airflow.api.auth.backend.session,airflow.api.auth.backend.basic_auth## Make sure that your user/name are configured properly - using the user/password that has admin# privileges in Airflow# Configure HTTP basic authorization: Basicconfiguration=airflow_client.client.Configuration(host="http://localhost:8080/api/v1",username='admin',password='admin')# Make sure in the [core] section, the  `load_examples` config is set to True in your airflow.cfg# or AIRFLOW__CORE__LOAD_EXAMPLES environment variable set to TrueDAG_ID="example_bash_operator"# Enter a context with an instance of the API clientwithairflow_client.client.ApiClient(configuration)asapi_client:errors=Falseprint('[blue]Getting DAG list')dag_api_instance=dag_api.DAGApi(api_client)try:api_response=dag_api_instance.get_dags()print(api_response)exceptairflow_client.client.OpenApiExceptionase:print("[red]Exception when calling DagAPI->get_dags:%s\n"%e)errors=Trueelse:print('[green]Getting DAG list successful')print('[blue]Getting Tasks for a DAG')try:api_response=dag_api_instance.get_tasks(DAG_ID)print(api_response)exceptairflow_client.client.exceptions.OpenApiExceptionase:print("[red]Exception when calling DagAPI->get_tasks:%s\n"%e)errors=Trueelse:print('[green]Getting Tasks successful')print('[blue]Triggering a DAG run')dag_run_api_instance=dag_run_api.DAGRunApi(api_client)try:# Create a DAGRun object (no dag_id should be specified because it is read-only property of DAGRun)# dag_run id is generated randomly to allow multiple executions of the scriptdag_run=DAGRun(dag_run_id='some_test_run_'+uuid.uuid4().hex,)api_response=dag_run_api_instance.post_dag_run(DAG_ID,dag_run)print(api_response)exceptairflow_client.client.exceptions.OpenApiExceptionase:print("[red]Exception when calling DAGRunAPI->post_dag_run:%s\n"%e)errors=Trueelse:print('[green]Posting DAG Run successful')# Get current configuration. Note, this is disabled by default with most installation.# You need to set `expose_config = True` in Airflow configuration in order to retrieve configuration.conf_api_instance=config_api.ConfigApi(api_client)try:api_response=conf_api_instance.get_config()print(api_response)exceptairflow_client.client.OpenApiExceptionase:print("[red]Exception when calling ConfigApi->get_config:%s\n"%e)errors=Trueelse:print('[green]Config retrieved successfully')iferrors:print('\n[red]There were errors while running the script - see above for details')else:print('\n[green]Everything went well')SeeREADMEfor full client API documentation.