@deepnote/reactivity

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

Reactivity and dependency graph for Deepnote notebooks

原始使用文档
文档目录6 节
  1. Requirements
  2. Overview
  3. Usage
  4. Basic Example
  5. Key Functions
  6. Core Concepts

@deepnote/reactivity

Reactivity and dependency graph for Deepnote notebooks.

Requirements

This package requires Python 3 and the jinja2 Python library to be installed on the system where it is running. The jinja2 library is used for parsing variable dependencies in SQL blocks.

You can install the requirement via pip:

pip install jinja2

By default, the package looks for python3 in the system path. You can override this by providing a pythonInterpreter path in the options of the main functions.

Overview

This package provides utilities for analyzing dependencies between Deepnote blocks to build a reactivity graph. It uses a Python-based AST analyzer to identify defined and used variables in various block types.

  • AST Analysis: Extracts variable definitions and usages across Python, SQL, button, big-number, notebook-function, and input-* blocks.
  • Dependency Tracking: Identifies how blocks depend on each other through variables.
  • Reactivity Support: Powers the reactive execution model by analyzing block content.

Usage

The primary entry point for the library is getDagForBlocks. It analyzes the content of the blocks and builds a Directed Acyclic Graph (DAG) representing their dependencies.

Basic Example

import { getDagForBlocks } from "@deepnote/reactivity";

const blocks = [
  // ... array of DeepnoteBlock objects
];

const { dag, newlyComputedBlocksContentDeps } = await getDagForBlocks(blocks);

// Access the dependency graph
console.log(dag.nodes);
console.log(dag.edges);

Key Functions

  • getDagForBlocks(blocks, options?): Builds the complete dependency graph of the notebook. This is useful for mapping out data flow and powering features like dependency visualizations. Use acceptPartialDAG: true in the options if you want to receive a graph even if some blocks have syntax errors. Supports pythonInterpreter option.
  • getDownstreamBlocks(blocks, blocksToExecute, options?): Identifies all blocks that need to be re-run when specific upstream blocks are executed or modified. This is the core function for implementing reactive execution, ensuring that the entire notebook remains consistent. Supports pythonInterpreter option.
  • getBlockDependencies(blocks, options?): A lower-level utility that extracts variable definitions and usages from block content using AST analysis. It is useful for inspecting the inputs and outputs of individual blocks without constructing the full graph. Supports pythonInterpreter option.

Core Concepts

  • Nodes: Each block in the notebook is a node in the DAG. Nodes contain information about inputVariables (variables used) and outputVariables (variables defined).
  • Edges: An edge exists from block A to block B if block B uses a variable defined by block A.
  • Reactivity: By understanding these dependencies, Deepnote can automatically determine which blocks need to be re-run when a variable is changed in an upstream block.

版本与发布记录

@deepnote/reactivity 共发布 11 个版本,首次发布于 2026/01/05;过去 12 个月发布了 11 个版本。

版本发布日期距今
2.0.0latest2026/11/056 天前
1.2.42026/10/1230 天前
1.2.32026/10/051 个月前
1.2.22026/08/132 个月前
1.2.12026/06/294 个月前
1.2.02026/02/238 个月前

关于 @deepnote/reactivity 的常见问题

@deepnote/reactivity 是什么?

Reactivity and dependency graph for Deepnote notebooks

如何安装 @deepnote/reactivity?

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

@deepnote/reactivity 支持 TypeScript 吗?

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

@deepnote/reactivity 支持 ESM 还是 CommonJS?

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

@deepnote/reactivity 可以商用吗?

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

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

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

@deepnote/reactivity 还在维护吗?

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