@deepnote/blocks

中文文档
5.0.0发布于 2026/11/05Apache-2.0TypeScriptESM + CJS近 30 天下载 1.1万

The blocks package defines the Deepnote Blocks.

原始使用文档
文档目录9 节
  1. Overview
  2. Supported Block Types
  3. Code & Data Blocks
  4. Input Blocks
  5. Display Blocks
  6. Text & Markdown Blocks
  7. Usage
  8. Python Code Generation
  9. Markdown Conversion

@deepnote/blocks

The blocks package defines the Deepnote Blocks.

Overview

This package provides TypeScript types and utilities for working with Deepnote notebook blocks, including:

  • Block Types: Code, SQL, Text, Markdown, Input, Visualization, Button, Big Number, Image, Separator
  • Python Code Generation: Convert blocks to executable Python code
  • Markdown Conversion: Convert text blocks to/from markdown format

Supported Block Types

Code & Data Blocks

  • code: Python code execution
  • sql: SQL query execution with variable assignment

Input Blocks

  • input-text: Single-line text input
  • input-textarea: Multi-line text input
  • input-checkbox: Boolean checkbox
  • input-select: Single or multi-select dropdown
  • input-slider: Numeric slider
  • input-file: File path selector
  • input-date: Date picker
  • input-date-range: Date range with presets (past 7 days, past month, etc.)

Display Blocks

  • visualization: Interactive charts using Vega-Lite
  • pivot-table: Code-free cross-tabulation of a DataFrame (beta)
  • big-number: KPI display with Jinja2 templates
  • button: Interactive button with variable control

Text & Markdown Blocks

  • text-cell-h1/h2/h3: Headings
  • text-cell-p: Paragraphs
  • text-cell-bullet: Bullet lists
  • text-cell-todo: Checkboxes
  • text-cell-callout: Highlighted notes
  • separator: Horizontal rule (<hr>)
  • image: Embedded images with alignment and sizing

Usage

Python Code Generation

import { createPythonCode } from "@deepnote/blocks";

// Code block
const codeBlock = {
  type: "code",
  content: 'print("Hello, world!")',
  // ...
};
createPythonCode(codeBlock); // 'print("Hello, world!")'

// SQL block
const sqlBlock = {
  type: "sql",
  content: "SELECT * FROM users",
  metadata: {
    deepnote_variable_name: "df_users",
    sql_integration_id: "abc-123",
  },
  // ...
};
createPythonCode(sqlBlock);
// df_users = _dntk.execute_sql('SELECT * FROM users', 'SQL_ABC_123', ...)

// Input checkbox
const checkboxBlock = {
  type: "input-checkbox",
  metadata: {
    deepnote_variable_name: "is_enabled",
    deepnote_variable_value: true,
  },
  // ...
};
createPythonCode(checkboxBlock); // is_enabled = True

// Input date range
const dateRangeBlock = {
  type: "input-date-range",
  metadata: {
    deepnote_variable_name: "date_range",
    deepnote_variable_value: "past7days",
  },
  // ...
};
createPythonCode(dateRangeBlock);
// from datetime import datetime as _deepnote_datetime, timedelta as _deepnote_timedelta
// date_range = [_deepnote_datetime.now().date() - _deepnote_timedelta(days=7), ...]

Markdown Conversion

import { createMarkdown, stripMarkdown } from "@deepnote/blocks";

const headingBlock = {
  type: "text-cell-h1",
  content: "Main Title",
  // ...
};

const markdown = createMarkdown(headingBlock); // "# Main Title"
const plainText = stripMarkdown(headingBlock); // "Main Title"

const todoBlock = {
  type: "text-cell-todo",
  content: "Complete task",
  metadata: { checked: true },
  // ...
};

createMarkdown(todoBlock); // "- [x] Complete task"

const separatorBlock = {
  type: "separator",
  content: "",
  // ...
};

createMarkdown(separatorBlock); // "<hr>"

const imageBlock = {
  type: "image",
  content: "",
  metadata: {
    deepnote_img_src: "https://example.com/image.png",
    deepnote_img_width: "500",
    deepnote_img_alignment: "center",
  },
  // ...
};

createMarkdown(imageBlock); // '<img src="https://example.com/image.png" width="500" align="center" />'

版本与发布记录

@deepnote/blocks 共发布 24 个版本,首次发布于 2025/11/01;过去 12 个月发布了 17 个版本。

版本发布日期距今
5.0.0latest2026/11/056 天前
4.8.12026/10/1230 天前
4.8.02026/10/051 个月前
4.7.02026/08/132 个月前
4.6.02026/06/294 个月前
4.5.12026/03/267 个月前

关于 @deepnote/blocks 的常见问题

@deepnote/blocks 是什么?

The blocks package defines the Deepnote Blocks.

如何安装 @deepnote/blocks?

在项目目录运行 npm install @deepnote/blocks,或使用 pnpm add / yarn add / bun add。

@deepnote/blocks 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@deepnote/blocks 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@deepnote/blocks 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.14.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@deepnote/blocks 可以商用吗?

@deepnote/blocks 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@deepnote/blocks 的下载量有多少?

根据 npm 官方下载统计,@deepnote/blocks 在 2026/10/12 – 2026/11/10 这 30 天内被下载 11,290 次,日均约 376 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@deepnote/blocks 还在维护吗?

最新版本 5.0.0 发布于 2026/11/05(6 天前);至今共发布 24 个版本,其中过去 12 个月发布了 17 个;首次发布于 2025/11/01。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。