Skip to main content

Airflow run Jupyter Notebook Remote

What is it?

architecture

This plugin is designed to allow the execution of Jupyter Notebooks remotely from within an Airflow DAG. By using the plugin, users can integrate and manage Jupyter Notebook workflows as part of their Airflow pipelines, ensuring that data analysis or machine learning code can be orchestrated and run automatically within the DAG scheduling system.

The plugin utilizes the Jupyter API to communicate with a Jupyter server, allowing for operations such as starting a kernel, running notebook cells, and managing sessions. It supports both HTTP requests for session and kernel management and WebSocket connections for sending code to execute inside the notebooks.

Package link: https://pypi.org/project/airflow-remote-jupyter-notebook/

Would you mind buying me a coffee?

If you find this library helpful, consider buying me a coffee! Your support helps maintain and improve the project, allowing me to dedicate more time to developing new features, fixing bugs, and providing updates.

coffee

Dependencies

Installation

Via Pypi Package:

$ pip install airflow-remote-jupyter-notebook

Manually

# run docker-compose to up Airfow and Jupyter Notebook containers
$ docker-compose up

Airfow plugin dependencies

Test dependences

How to contribute

Please report bugs and feature requests at https://github.com/marcelo225/airflow-remote-jupyter-notebook/issues

Credits

Lead Developer - Marcelo Vinicius

Run remote jupyter notebook using Airflow

# in root project folder
$ docker-compose up

Plugin Usage

from jupyter_plugin.plugin import JupyterDAG # <--------- How to import this plugin
from airflow.models import Variable
import datetime

with JupyterDAG(
    'test_dag',     
    jupyter_url=Variable.get('jupyter_url'),
    jupyter_token=Variable.get('jupyter_token'),
    jupyter_base_path=Variable.get('jupyter_base_path'),
    max_active_runs=1,
    default_args={
        'owner': 'Marcelo Vinicius',
        'depends_on_past': False,
        'start_date': datetime.datetime(2021, 1, 1),
        'email_on_failure': False,
        'email_on_retry': False,
        'retries': 2        
    },
    description=f'DAG test to run some remote Jupyter Notebook file.',
    schedule=2,
    catchup=False
) as dag:

    test1 = dag.create_jupyter_remote_operator(task_id="test1", notebook_path=f"notebooks/test1.ipynb")
    test2 = dag.create_jupyter_remote_operator(task_id="test2", notebook_path=f"notebooks/test2.ipynb")
    test3 = dag.create_jupyter_remote_operator(task_id="test3", notebook_path=f"notebooks/test3.ipynb")

test1 >> test2 >> test3
DAG Attributes Description
jupyter_url Jupyter URL server with HTTP or HTTPS
jupyter_token Jupyter Authentication Token
jupyter_base_path Base path where your Jupyter notebooks are stored
Task Creation Explanation
create_jupyter_remote_operator Method from the JupyterDAG class that creates a task to execute a specified Jupyter notebook on a remote server.
task_id A unique identifier for the task, used for tracking and logging within Airflow.
notebook_path Specifies the path to the Jupyter notebook to be executed, relative to the base path.

Run tests

To test the scripts within the Airflow environment, you can use the following command. This will run all tests located in the /home/airflow/tests directory inside the container:

$ docker-compose exec airflow pytest /home/airflow/tests

Release files for airflow-remote-jupyter-notebook 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for airflow-remote-jupyter-notebook 0.0.3
File Size Uploaded
airflow_remote_jupyter_notebook-0.0.3.tar.gz 4.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for airflow-remote-jupyter-notebook 0.0.3
File Interpreter ABI Platform
airflow_remote_jupyter_notebook-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 7.7 kB

Release files / airflow_remote_jupyter_notebook-0.0.3.tar.gz

Download URL airflow_remote_jupyter_notebook-0.0.3.tar.gz
Size 4.2 kB
Tags Source
SHA-256 checksum
How to use checksums
019118e47f7c07432aa12c5b6fb281eaf8159887d03dcf636890e1aa1e268376
BLAKE2b-256 checksum
How to use checksums
65ccf5807929efea646f754b68e0690912b9dc1d40f0099f1035a16e12878ecb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.18

Release files / airflow_remote_jupyter_notebook-0.0.3-py3-none-any.whl

Download URL airflow_remote_jupyter_notebook-0.0.3-py3-none-any.whl
Size 3.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b6dfdb3efcf17fd609be89b60d4ea186689b9b18cd20313f6014477411aef47b
BLAKE2b-256 checksum
How to use checksums
7ff8277d98296950838f742632dc6218c891bb769b4400c938c8ae1be71d2fd8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.8.18

Release history Release notifications | RSS feed

This release

0.0.3 This release

2 release files

0.0.2

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page