No tienes acceso a esta clase

¬°Contin√ļa aprendiendo! √önete y comienza a potenciar tu carrera

Python Operator

13/29
Recursos

Aportes 18

Preguntas 4

Ordenar por:

¬ŅQuieres ver m√°s aportes, preguntas y respuestas de la comunidad?

Me gusta la parte de que se se sigan podiendo reutilizar funciones, dejo ejemplo

from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime

def print_hello(country, **kwargs):
    print(f'I am processing this {country}')


with DAG(dag_id='pythonoperator'
        , description='Utilizando python operator'
        , start_date=datetime(2023, 6, 7)
        , schedule_interval='@once') as dag:


    t1 = PythonOperator(task_id='process_ar'
                        , python_callable=print_hello
                        , op_kwargs={'country':'AR'})

    t2 = PythonOperator(task_id='process_uy'
                        , python_callable=print_hello
                        , op_kwargs={'country':'UY'})

    t1 >> t2 

This is wonderful!

from airflow import DAG
from airflow.operators.python import PythonOperator

from datetime import datetime


def print_hello():
    print('Hello people from python funtion')

with DAG(
    dag_id='python_operator',
    description='Fisrt dag using python operator',
    schedule_interval='@once',
    start_date=datetime(2022,8,1)
    ) as dag:
    
    t1 = PythonOperator(
        task_id = 'hello_with_python',
        python_callable = print_hello
    )
    ```
![](https://static.platzi.com/media/user_upload/image-fea1f5a4-84d9-40f6-90b8-f96dabcf813f.jpg)

ūüėÉ

from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime


def print_hello():
    return print('hello world with python in airflow')


with DAG(dag_id='primer_dag_python',
         schedule_interval='@once',
         start_date=datetime(2022, 7, 1)) as dag:

    t1 = PythonOperator(task_id='primer_task_python',
                        python_callable=print_hello)

from airflow import DAGfrom airflow.operators.python import PythonOperatorfrom datetime import datetime def print\_hello():    print("Hola de pruebas.") with DAG(dag\_id="pythonoperator",         description="Nuestro primer DAG utilizando python operator",         schedule\_interval="@once",         start\_date=datetime(2022, 8, 1)) as dag:        t1 = PythonOperator(        task\_id="hello\_with\_python",        python\_callable=print\_hello    ) t1
![](https://static.platzi.com/media/user_upload/image-16a6a8a4-d095-4e6f-8edb-e1f77c424315.jpg)
![](https://static.platzi.com/media/user_upload/image-bfb8e948-9816-4ecf-8957-53b5292dc300.jpg)

Ahora con Python Operator:

Si quisiera usar por ejemplo la librería pandas, donde se instala para usarla en el DAG?
from airflow import DAG
from datetime import datetime
from airflow.operators.python import PythonOperator

def print_hello():
    print("HELLO PAPUS")

with DAG(dag_id="pythonoperator",
         description="Nuestro primer DAG utilizando python ope",
         schedule_interval="@once",
         start_date =datetime(2022,12,6)) as dag:


    t1 = PythonOperator(task_id="hello_with_python",
                        python_callable=print_hello)

    t1                        ```

Holis from python operator!!