REST API и CLI — обзор модуля
В Airflow 2.0 стал stable REST API v1 на Flask-RESTful. Это позволяет автоматизировать всё через HTTP: trigger DAGs, monitor execution, clear tasks, manage Connections. Этот модуль учит правильно использовать API в CI/CD контексте.
Уроки модуля
| # | Урок | Что внутри |
|---|---|---|
| 01 | Обзор модуля | Текущий урок |
| 02 | REST API v1 endpoints | /api/v1/* — основные endpoints |
| 03 | Authentication: basic, JWT, OAuth | FAB auth backends |
| 04 | Common automation patterns | Trigger DAGs externally, monitor state, clear |
| 05 | CLI deep dive | airflow dags / tasks / db / pools / connections |
| 06 | Programmatic access | Python client, custom scripts |
REST API v1 — ключевые endpoints
# Trigger DAG run
POST /api/v1/dags/{dag_id}/dagRuns
{
"logical_date": "2026-05-12T00:00:00Z",
"conf": {"key": "value"}
}
# Get DAG run state
GET /api/v1/dags/{dag_id}/dagRuns/{dag_run_id}
# List TaskInstances
GET /api/v1/dags/{dag_id}/dagRuns/{run_id}/taskInstances
# Clear tasks
POST /api/v1/dags/{dag_id}/clearTaskInstances
OpenAPI 3 spec доступен на /api/v1/openapi.yaml.
Authentication backends
[api]
auth_backends = airflow.api.auth.backend.basic_auth,airflow.api.auth.backend.session
Доступные backends:
basic_auth— HTTP Basic с FAB userssession— cookie-based (для AJAX из UI)kerberos_authairflow.providers.amazon.aws.auth_manager.aws_auth_manager— AWS IAM (через MWAA)
Common automation patterns
Trigger DAG из external system
curl -X POST \
-u airflow:airflow \
-H "Content-Type: application/json" \
-d '{"conf": {"source_path": "s3://..."}}' \
http://airflow:8080/api/v1/dags/my_dag/dagRuns
Monitor execution
curl -u airflow:airflow \
http://airflow:8080/api/v1/dags/my_dag/dagRuns/manual__2026-05-12T10:00:00 \
| jq '.state'
Из Python через requests
import requests
from requests.auth import HTTPBasicAuth
response = requests.post(
"http://airflow:8080/api/v1/dags/my_dag/dagRuns"
auth=HTTPBasicAuth("airflow", "airflow"),
json={"conf": {"date": "2026-05-12"}}
)
Killer takeaway
Для CI/CD integration используйте REST API v1, не SSH в scheduler container. REST API designed для automation: idempotent requests, structured errors, FAB-based auth.
Что нового в 3.x (обзор)
В Airflow 3.0 REST API v2 на FastAPI с автогенерируемым OpenAPI и React-friendly contract. Также появляется airflowctl provider — remote CLI без захода в scheduler container. Обе фичи покрываются в финальном модуле upgrade path.