Airflow run Jupyter Notebook Remote
What is it?
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.
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
- Look at requirements.txt
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
- Open http://localhost:8080 in your web browser to open Airflow
- Open http://localhost:8888 in your web browser to open Jupyter Notebook, when you need it
- Run
test_dagin Airflow
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
Metadata
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| airflow_remote_jupyter_notebook-0.0.3.tar.gz | 4.2 kB | Without provenance | Details for airflow_remote_jupyter_notebook-0.0.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| airflow_remote_jupyter_notebook-0.0.3-py3-none-any.whl | Python 3 | none | any | Details for airflow_remote_jupyter_notebook-0.0.3-py3-none-any.whl |
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
|
Security for airflow-remote-jupyter-notebook 0.0.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.