Introduction à Apache Airflow

Introduction à Apache Airflow en Python

Mike Metzger

Data Engineer

Qu’est-ce que l’ingénierie des données ?

L’ingénierie des données, c’est :

  • Transformer toute action sur les données en un processus fiable, reproductible et maintenable.
Introduction à Apache Airflow en Python

Qu’est-ce qu’un workflow ?

Un workflow, c’est :

  • Un ensemble d’étapes pour réaliser une tâche d’ingénierie des données
    • Par exemple : télécharger des fichiers, copier des données, filtrer des informations, écrire dans une base, etc.
  • De complexité variable
  • Un terme dont le sens varie selon le contexte

Exemple de workflow

Introduction à Apache Airflow en Python

Qu’est-ce qu’Airflow ?

Airflow est une plateforme pour programmer des workflows, incluant :

  • Création
  • Planification
  • Supervision

Logo Airflow

Introduction à Apache Airflow en Python

Airflow (suite)

  • Peut exécuter des programmes dans n’importe quel langage, mais les workflows sont écrits en Python
  • Implémente les workflows en DAGs : Directed Acyclic Graphs
  • Accès via le code, la ligne de commande ou l’interface web / API REST

Logo Airflow

1 https://airflow.apache.org/docs/stable/
Introduction à Apache Airflow en Python

Autres outils de workflows

Autres outils :

  • Luigi
  • SSIS
  • Scripts Bash

Logo Luigi

Logo Bash

Logo SSIS

Introduction à Apache Airflow en Python

Introduction rapide aux DAGs

Un DAG signifie Directed Acyclic Graph (graphe orienté acyclique)

  • Dans Airflow, il représente l’ensemble des tâches de votre workflow.
  • Composé des tâches et de leurs dépendances.
  • Créé avec divers détails : nom, date de début, propriétaire, etc.
  • Approfondi dans la prochaine leçon.

Exemple de DAG

Introduction à Apache Airflow en Python

Exemple de code de DAG

Définition simple d’un DAG :

etl_dag = DAG(
    dag_id='etl_pipeline',
    default_args={"start_date": "2024-01-08"}
)
Introduction à Apache Airflow en Python

Exécuter un workflow dans Airflow

Exécuter une tâche Airflow simple

airflow tasks test <dag_id> <task_id> [execution_date]

Avec un DAG nommé example-etl, une tâche download-file le 2024-01-10 :

airflow tasks test example-etl download-file 2024-01-10
Introduction à Apache Airflow en Python

Passons à la pratique !

Introduction à Apache Airflow en Python

Preparing Video For Download...