Airflow CLI Commands

The Airflow command line interface (CLI) lets you control Airflow from a terminal. You can list pipelines, start runs, test single tasks, and manage users without opening the web page. Developers rely on the CLI for fast checks, scripts, and automation.

Why the CLI Matters

A web page needs clicks. A terminal command needs one line. When you test a new task twenty times in a row, typing a command saves a lot of time. Servers without a screen also depend on the CLI, since no browser is available there.

You type a command
        │
        ▼
┌──────────────────┐
│  airflow CLI     │
└────────┬─────────┘
         │ reads / writes
         ▼
┌──────────────────┐
│ Metadata database│
└──────────────────┘

Command Structure

Every command follows the same pattern: the word airflow, a group name, and an action.

airflow  <group>  <action>  [options]

airflow  dags     list
airflow  tasks    test   my_dag  my_task  2024-01-15

Add --help to any command to see its options.

airflow dags --help

DAG Commands

CommandWhat It Does
airflow dags listShows every DAG Airflow found
airflow dags trigger my_dagStarts a new run right now
airflow dags pause my_dagStops new scheduled runs
airflow dags unpause my_dagAllows scheduled runs again
airflow dags list-runs -d my_dagLists past runs of one DAG
airflow dags list-import-errorsShows files that failed to load
airflow dags test my_dag 2024-01-15Runs the whole DAG once in your terminal

Task Commands

Task commands work on one task at a time. They help you check a single step without running the whole pipeline.

airflow tasks list my_dag
airflow tasks test my_dag extract 2024-01-15
airflow tasks state my_dag extract 2024-01-15

The tasks test command runs the task code and prints the logs on screen. It does not save the result in the database, so you can repeat it safely.

Database Commands

airflow db migrate     # create or upgrade tables
airflow db check       # confirm the database responds
airflow db clean --clean-before-timestamp "2024-01-01"

Run db migrate after you install or upgrade Airflow. Older versions use db init and db upgrade for the same purpose. The db clean command removes old records and keeps the database small.

Connection, Variable, and User Commands

airflow connections list
airflow connections add my_db --conn-type postgres \
    --conn-host localhost --conn-login admin --conn-password secret

airflow variables set env production
airflow variables get env

airflow users create --username admin --firstname Sam \
    --lastname Lee --role Admin --email sam@example.com

Service Commands

CommandService Started
airflow schedulerScheduler
airflow webserverWeb server (Airflow 2)
airflow triggererTriggerer
airflow standaloneAll services on one machine, for learning

Information Commands

airflow version
airflow config get-value core dags_folder
airflow info

The airflow info command prints the version, paths, and tool details. Support teams ask for this output when you report a problem.

A Typical Daily Workflow

1. Write or edit the DAG file
2. airflow dags list-import-errors     → file loads cleanly?
3. airflow tasks test  ...             → each task works alone?
4. airflow dags test   ...             → whole flow works?
5. airflow dags unpause my_dag         → schedule goes live

Tips for Safe CLI Use

  • Prefer tasks test and dags test while developing, since they leave no run history.
  • Check which environment you use before you run trigger or pause on a production server.
  • Keep passwords out of shell history by using environment variables or a secrets backend.
  • Save repeated command sequences in a small shell script.

Key Takeaways

  • Commands follow the pattern airflow, group, action.
  • The test commands give fast feedback without side effects.
  • The CLI manages DAGs, tasks, connections, variables, users, and the database.