Oct 28 2022 · Aleksandra Płońska, Piotr Płoński

The 3 ways to share password protected Jupyter Notebook

3 ways to share password protected Jupyter NotebookYou created an analysis in Jupyter Notebook and would like to share it online with selected persons. In this article, I will show you how to add password protection to the selected Jupyter Notebook and share it only with authorized people.

1. Share on the hosting platform

There are hosting platforms like Netlify or Vercel that allows you to add password protection to a static website. It will require a paid plan for both services. What is more, you need to convert your notebook into a static HTML file (it can be done with the nbconvert tool). Your users can view the notebook without the option to interact with it.

2. Encrypt Jupyter Notebook

There is a staticrypt library that can encrypt HTML files with your passphrase. You can export notebook to HTML file and use staticrypt to encode the file with a password. You upload encrypted notebook file to your hosting platform (AWS S3, Netlify, Vercel). When the user wants to open the website, it will see the password prompt window. The notebook is shown after the correct password is entered.

Steps to encrypt Jupyter Notebook with password:

  1. Convert Jupyter Notebook to an HTML file.
  2. Use staticrypt website to generate encrypted HTML. You can also use staticrypt locally, please check their documentation for details.
  3. Download the encrypted HTML file.

The staticrypt website for encrypting HTML file: Encrypt notebook

View of password protected notebook: Protected Page Notebook

The password view can be customized with HTML and CSS.

3. Mercury

Previous methods are good for sharing static Jupyter Notebook, which means your users can't interact with notebooks. They can't change variables' values and execute notebook cells.

There is an open-source framework called Mercury for sharing Jupyter Notebooks as interactive web applications. It adds widgets to the Jupyter Notebook with a YAML header. There is a share parameter in the YAML configuration. It can be used to share a notebook with selected users. You can read more in the documentation.

The login view for Mercury: Login to Mercury

Example YAML header that shares notebook only with authenticated users:

title: Some title
description: Some app description
share: private
params:
    input: text
    label: Please enter text

Summary

There are several options for sharing password protected Jupyter Notebook. It can be shared as static HTML. The protection is provided by the hosting platform or encrypting library. If you are looking to share an interactive Jupyter Notebook with selected persons, then you can try the Mercury framework.