Using the Command Line Interface¶
This document is meant to give an overview of all common tasks while using the CLI.
For more information on CLI commands, see Command Line Interface Reference
Set Up connection to a remote Airflow instance¶
For some functions the CLI can use the REST API. To configure the CLI to use the API when available configure as follows:
[cli] api_client = airflow.api.client.json_client endpoint_url = http://<WEBSERVER>:<PORT>
Set Up Bash/Zsh Completion¶
When using bash (or
zsh) as your shell,
airflow can use
argcomplete for auto-completion.
For global activation of all argcomplete enabled python applications run:
For permanent (but not global) airflow activation, use:
register-python-argcomplete airflow >> ~/.bashrc
For one-time activation of argcomplete for airflow only, use:
eval "$(register-python-argcomplete airflow)"
If you’re using
zsh, add the following to your
autoload bashcompinit bashcompinit eval "$(register-python-argcomplete airflow)"
Creating a Connection¶
For information on creating connection using CLI, see Command Line Interface Reference
Exporting DAGs structure to images¶
The application has the functionality of saving DAG to image file. You can attach them to the documentation for the documentation, or send another without having to send the DAG file and install the application at the other person. However, you need to have Graphviz installed.
For example, if you want to export
example_complex DAG then you can use the following command:
airflow show_dag example_complex
After passing the
dag_id parameter itself, the command will print rendered DAG structure (similar to Graph View)
to the screen in the DOT format.
It is possible to save the file in a different format. To do this, add the switch
If you want to save files as PNG, you can use the following command:
airflow show_dag example_complex --save example_complex.png
An example image file may look as follow:
The following file formats are supported:
By default, the application search for DAGs in the directory specified in
dags_folder option in
[core] section specified in the file
airflow.cfg. You can change it with the
Display DAGs structure¶
Sometimes you will work on DAGs that contain complex dependencies. It is helpful then to preview the DAG to see if it is correct.
Other terminals do not support the display of high-quality graphics. You can convert the image to a text form, but its resolution will prevent you from reading it.
To do this, you should use the
--imgcat switch in the
airflow dags show command. For example, if you
want to display
example_bash_operator DAG then you can use the following command:
airflow show_dag example_bash_operator --imgcat
You will see a similar result as in the screenshot below.