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" : [
      ]
    }
  ]
}

客户端界面

主界面布局:

android笔记本代码 代码 笔记本_android笔记本代码

(受限于图片编辑工具内的输入法无法切换为中文,图片中的注释以英文书写)

工具条中的“Cell”部分有下拉框可选择活跃单元格的内容类型(Text, Scala, Python等),单元格区域内的顶部也提供了设置类型的下拉框,不过,这里的下拉框仅在单元格是代码类型(Scala、Python等)才会显示,如果要在文本(Text)和代码(Scala, Python等)类型间变换时则只能用工具条中的下拉框。

笔记本配置项和依赖包(Configuration & Dependencies):

android笔记本代码 代码 笔记本_android笔记本代码_02

部署

下载
下载最新程序包后解压。

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)。