Polynote——編程筆記本環境


Polynote

Polynote,是一個編程筆記本環境(programming notebook),由網飛(Netflix)開源。

編程筆記本(代碼筆記本),如python中的jupyter notebook,是若干代碼筆記的集合。代碼筆記即是一些片段。

編程筆記本環境,是提供代碼筆記編輯和存儲、執行、結果顯示和存儲的編程環境。在代碼筆記本環境中,代碼筆記被放在“單元格”內,一個單元格即對應一個筆記。代碼筆記本環境一般提供存儲最近一次運行結果的功能。

Polynote的服務端是基於scala的,與用戶的交互通過Web實現(如網頁瀏覽器)。

優點:

  • 支持多種語言/環境(scala, python, spark)
  • 支持多語言代碼的混合
  • 代碼自動補全
  • 富文本
  • 支持LaTex數學公式
  • 跟蹤代碼執行任務
  • 實時高亮正在執行的代碼片段
  • 數據可視化

符號表

當前代碼可用的符號(變量)是位置在當前代碼之前的單元格中的符號。而其他有的筆記本環境會將所有符號視為全局量,其使得任一單元格可使用所有單元格中的符號。

(raw content of notebook)

{
  "metadata" : {
    "config" : {
      "dependencies" : {
        
      },
      "exclusions" : [
      ],
      "repositories" : [
      ],
      "sparkConfig" : {
        
      }
    }
  },
  "nbformat" : 4,
  "nbformat_minor" : 0,
  "cells" : [
    {
      "cell_type" : "markdown",
      "execution_count" : 0,
      "metadata" : {
        "language" : "text"
      },
      "language" : "text",
      "source" : [
        "# Title Here<br>\n",
        "\n",
        "\n",
        "text cell,* **supporting*** rich** *text* , and latex equations, like  $\\bm A=\\bm U \\bm\\Sigma \\bm V^T$.<br>\n",
        "\n",
        "\n"
      ],
      "outputs" : [
      ]
    },
    {
      "cell_type" : "code",
      "execution_count" : 1,
      "metadata" : {
        "cell.metadata.exec_info" : {
          "startTs" : 1573438795595,
          "endTs" : 1573438795820
        },
        "language" : "scala"
      },
      "language" : "scala",
      "source" : [
        "println(\"hello world from polynote in scala\")\n",
        "val x = 100\n"
      ],
      "outputs" : [
        {
          "name" : "stdout",
          "text" : [
            "hello world from polynote in scala",
            "\n"
          ],
          "output_type" : "stream"
        }
      ]
    },
    {
      "cell_type" : "code",
      "execution_count" : 2,
      "metadata" : {
        "cell.metadata.exec_info" : {
          "startTs" : 1573438892501,
          "endTs" : 1573438892670
        },
        "language" : "python"
      },
      "language" : "python",
      "source" : [
        "print('hello world in python')\n",
        "y = x / 2\n",
        "print(f'y: {y}')\n"
      ],
      "outputs" : [
        {
          "name" : "stdout",
          "text" : [
            "hello world in python",
            "\n",
            "y: 50.0",
            "\n"
          ],
          "output_type" : "stream"
        }
      ]
    },
    {
      "cell_type" : "code",
      "execution_count" : 3,
      "metadata" : {
        "language" : "sql"
      },
      "language" : "sql",
      "source" : [
        "SELECT * from my_sample_table;"
      ],
      "outputs" : [
      ]
    },
    {
      "cell_type" : "markdown",
      "execution_count" : 4,
      "metadata" : {
        "language" : "text"
      },
      "language" : "text",
      "source" : [
        "# Another Text\n",
        "\n",
        "<div>Actually, text cell is backed end by <i>markdown</i>.<br></div>"
      ],
      "outputs" : [
      ]
    }
  ]
}

客戶端界面

主界面布局:
界面布局

(受限於圖片編輯工具內的輸入法無法切換為中文,圖片中的注釋以英文書寫)

工具條中的“Cell”部分有下拉框可選擇活躍單元格的內容類型(Text, Scala, Python等),單元格區域內的頂部也提供了設置類型的下拉框,不過,這里的下拉框僅在單元格是代碼類型(Scala、Python等)才會顯示,如果要在文本(Text)和代碼(Scala, Python等)類型間變換時則只能用工具條中的下拉框。

筆記本配置項和依賴包(Configuration & Dependencies):

部署

下載
下載最新程序包后解壓。

tar -xzvf polynote-dist.tar.gz

Python支持:需要安裝python3, pip3,然后利用pip3命令安裝依賴包:

pip3 install jep jedi pyspark virtualenv

Spark支持:……

配置:文件config.yml(不存在則手動創建),程序包中附帶了一個配置模板,文件名config-template.yml

啟動

./polynote

默認在地址 http://127.0.0.1:8192 提供客戶端服務。
筆記數據默認存儲在安裝目錄下的notebooks目錄。

注意,Polynote暫無安全機制(版本 0.2)。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM