@dataform/cli

中文文档
3.1.5发布于 2026/11/10Apache-2.0CommonJS近 30 天下载 44.1万

Dataform command line interface.

原始使用文档
文档目录25 节
  1. Installation
  2. Invocation
  3. Global behavior
  4. Commands
  5. init
  6. install
  7. init-creds
  8. compile
  9. test
  10. run
  11. format
  12. Shared project-config flags
  13. Credentials file
  14. Example use cases
  15. First-time project setup
  16. Compiling and inspecting a project without touching the war…
  17. Running unit tests before deploying changes
  18. Running only part of a pipeline
  19. Validating a run without applying changes
  20. Bounding how long a run is allowed to take
  21. Targeting a different environment for one invocation
  22. Iterating on SQLX during development
  23. Checking formatting without modifying files
  24. Tracking and labeling jobs from a run
  25. Emitting lineage events for a run

Dataform CLI Reference

This document is a complete reference for the dataform command line interface. The command list, usage lines and argument/option tables are generated from the CLI source in this repository (cli/), so they match dataform help. It also covers practical example use cases.

For conceptual documentation (project structure, SQLX syntax, the JavaScript API, etc.) see the root readme and the hosted Dataform CLI guide.

Installation

npm i -g @dataform/cli

Invocation

dataform <command> [project-dir] [options]

project-dir is optional for every command and defaults to . (the current directory). It is resolved with tilde-expansion, so ~/my-project works. project-dir can be passed either positionally (dataform compile my-project) or as a named flag (dataform compile --project-dir=my-project).

Run dataform with no arguments, or dataform help, to print the list of commands. Run dataform help <command> or dataform <command> --help for a command's full flag list.

Global behavior

  • --help — shows help for the current command.
  • --version — prints the installed @dataform/cli version number.
  • Strict parsing — unknown commands or flags are rejected with an error, and the CLI suggests the closest matching command name for typos.
  • Colored output — output is colorized by default. Set NO_COLOR=1 (or true/yes) to disable it.
  • Lineage debug logging — set DATAFORM_LINEAGE_DEBUG=1 to enable verbose logging from the OpenLineage emitter used by run --emit-lineage.

Commands


init

dataform init [project-dir] [default-database] [default-location]

Creates a new Dataform project (workflow_settings.yaml, .gitignore, definitions/, and includes/) in project-dir. Fails if workflow_settings.yaml, package.json, or dataform.json already exists in project-dir.

Positional arguments

ArgumentRequiredDescription
project-dirNo (default .)The Dataform project directory.
default-databaseYesThe default database to use, equivalent to Google Cloud Project ID.
default-locationNoThe default location to use (optional). If omitted, `defaultLocation` is not written to `workflow_settings.yaml` and the `location` from `.df-credentials.json` is used instead; if that is also unset, BigQuery chooses the location dynamically. See https://cloud.google.com/bigquery/docs/locations for supported values.

project-dir is the directory to create the project in. All three positional arguments can also be passed as named flags (--project-dir, --default-database, --default-location), e.g. dataform init my_project --default-database=my-gcp-project-id --default-location=US.

Options

FlagTypeDefaultDescription
--icebergbooleanfalseInitialize the project with workflow-level Iceberg tables configuration.

When --iceberg is set, init prompts interactively for an Iceberg bucket name, table folder root/subpath, and connection.


install

dataform install [project-dir]

Installs a project's NPM dependencies (via npm i --ignore-scripts) as declared in the project's package.json.

Positional arguments

ArgumentRequiredDescription
project-dirNo (default .)The Dataform project directory.

Options

None.

Note: for projects that specify dataformCoreVersion in workflow_settings.yaml, @dataform/core is installed automatically in an isolated temporary directory at compile/run time, and running dataform install throws an error (No installation is needed when using workflow_settings.yaml, as packages are installed at runtime.). Use dataform install only when managing @dataform/core and external dependencies via package.json (without dataformCoreVersion in workflow_settings.yaml).


init-creds

dataform init-creds [project-dir]

Interactively creates a .df-credentials.json file in project-dir that Dataform uses to connect to BigQuery. Only BigQuery is currently supported.

Prompts for:

  1. Dataset location (US, EU, a custom region name, or auto). Choosing auto leaves location out of the credentials file so BigQuery chooses the location dynamically.
  2. Authentication method — Application Default Credentials (ADC) or a JSON service account key file.
    • ADC: prompts for your billing project ID.
    • JSON key: prompts for the path to a downloaded service account key file.
  3. A service account to impersonate (optional, press Enter to skip). It's saved as impersonateServiceAccount, see Credentials file.

Positional arguments

ArgumentRequiredDescription
project-dirNo (default .)The Dataform project directory.

Options

FlagTypeDefaultDescription
--test-connectionbooleantrueIf true, a test query will be run using your final credentials.

compile

dataform compile [project-dir]

Compiles the project and prints a summary (or JSON / Graphviz DOT representation) of the compiled dependency graph without executing it against your warehouse. Useful for validating a project and inspecting its structure.

Positional arguments

ArgumentRequiredDescription
project-dirNo (default .)The Dataform project directory.

Options

FlagTypeDefaultDescription
--jsonbooleanfalseOutputs the result as JSON instead of human-readable text.
--dotbooleanfalseOutputs a Graphviz DOT representation of the compiled project. Mutually exclusive with --json.
--verbosebooleanfalseEnables verbose compilation output. Mutually exclusive with --quiet.
--quietbooleanfalseLess verbose compilation output. Mutually exclusive with --verbose.
--watchbooleanfalseWatches the project directory and recompiles on changes.
--timeoutstring'60s'Duration to allow project compilation to complete, e.g. '1s', '10m'.
--output-actionsarray—Filters the printed output to these actions (comma-separated or repeatable). Each entry is an action name or a fully-qualified database.schema.name target. The whole project is still compiled.
--output-tagsarray—Filters the printed output to actions with any of these tags (comma-separated or repeatable).
--output-include-depsboolean—Also includes upstream dependencies of the selected actions in the output. Requires --output-actions or --output-tags.
--output-include-dependentsboolean—Also includes downstream dependents of the selected actions in the output. Requires --output-actions or --output-tags.
Project-config overrides——See Shared project-config flags.

Notes

  • --json outputs the compiled graph and can't be combined with --dot.
  • --watch ignores node_modules, recompiles with a debounce of 500ms, and runs until interrupted with Ctrl+C.
  • --output-actions, --output-tags, --output-include-deps and --output-include-dependents only prune what's printed; the whole project still compiles. --output-actions entries are matched exactly (no * wildcard expansion).

test

dataform test [project-dir]

Compiles the project and runs its unit tests (type: "test" actions) against BigQuery.

Positional arguments

ArgumentRequiredDescription
project-dirNo (default .)The Dataform project directory.

Options

FlagTypeDefaultDescription
--credentialsstring.df-credentials.jsonPath to the credentials JSON file to use.
--timeoutstring'60s'Duration to allow project compilation to complete, e.g. '1s', '10m'.
--jsonbooleanfalseOutputs the result as JSON instead of human-readable text.
Project-config overrides——See Shared project-config flags.

--json outputs the test results as JSON.

Exits with code 1 if any test fails, if the project fails to compile, or if no unit tests are found. Exits 0 if all tests pass.


run

dataform run [project-dir]

Compiles and executes the project against BigQuery (or validates it with --dry-run).

Positional arguments

ArgumentRequiredDescription
project-dirNo (default .)The Dataform project directory.

Options

FlagTypeDefaultDescription
--dry-runboolean—Validates the run SQL with BigQuery without applying any changes to the warehouse.
--run-testsboolean—Requires the project's unit tests to pass before executing; aborts the run if any test fails.
--action-retry-limitnumber0Retries idempotent actions up to this many times on failure.
--actionsarray—Actions to run (comma-separated or repeatable). Each entry is an action name or a fully-qualified database.schema.name target.
--tagsarray—Tags to filter the actions to run (comma-separated or repeatable).
--include-depsboolean—Also runs upstream dependencies of the selected actions. Requires --actions or --tags.
--include-dependentsboolean—Also runs downstream dependents of the selected actions. Requires --actions or --tags.
--full-refreshbooleanfalseForces incremental tables (unless marked protected) to be rebuilt from scratch.
--credentialsstring.df-credentials.jsonPath to the credentials JSON file to use.
--jsonbooleanfalseOutputs the result as JSON instead of human-readable text.
--timeoutstring'60s'Duration to allow project compilation to complete, e.g. '1s', '10m'.
--execution-timeoutstring—Wall-clock deadline for the entire run (compile + all actions). When it fires, in-flight actions are cancelled and pending actions are skipped. Off by default. Examples: '10m', '2h'.
--jit-timeoutstring—Per-model JiT compilation worker timeout. Each JiT action gets its own fresh deadline, independent of --execution-timeout. When unset, no per-model cap is applied and only --execution-timeout bounds JiT work. Examples: '30s', '2m'.
--job-prefixstring—Adds an additional prefix to BigQuery job IDs, in the form dataform-<job-prefix>-.
--job-labelsstring—Comma-separated list of labels to add to BigQuery jobs, e.g. 'key1=val1,key2=val2'. Also applied to unit tests with --run-tests. Overrides job labels and table labels that use the same key.
--emit-lineageboolean—If set, emits OpenLineage RunEvents to Knowledge Catalog Lineage for each executed action. Overrides workflow_settings.yaml lineage.enabled when specified. See https://github.com/dataform-co/dataform/blob/main/docs/lineage.md.
--build-onlybooleanfalseOnly builds the execution graph without submitting any queries to BigQuery. JiT actions are not compiled. Note that --dry-run and --run-tests will be ignored if combined with --build-only.
Project-config overrides——See Shared project-config flags.

Notes

  • --actions entries are matched exactly: * wildcards are not expanded, and a bare action name that matches several actions is an error.
  • --full-refresh only affects incremental tables; regular tables and views are always rebuilt.
  • --json outputs the run result as JSON and is only supported together with --dry-run; plain run --json is rejected.
  • --timeout bounds compilation only, not execution. If it's set without --execution-timeout, run prints a warning reminding you of that.
  • --job-labels override defaultJobLabels, action jobLabels and table labels that use the same key.
  • --emit-lineage requires the Data Lineage API (datalineage.googleapis.com) to be enabled and the roles/datalineage.producer role; for configuration and troubleshooting, see the Data Lineage guide.

Exit codes: 0 on success, 1 if compilation fails, a BigQuery job would get more than 64 labels (checked before any action or unit test runs), unit tests fail (with --run-tests), the run fails, times out, or is cancelled (Ctrl+C).


format

dataform format [project-dir]

Formats .sqlx and .js files in the project using Dataform's built-in formatter.

Positional arguments

ArgumentRequiredDescription
project-dirNo (default .)The Dataform project directory.

Options

FlagTypeDefaultDescription
--actionsarray{definitions,includes}/**/*.{js,sqlx}Glob patterns of files to format, relative to the project directory (comma-separated or repeatable).
--ignore-js-filesbooleanfalseIf set, only formats .sqlx files (skips .js files).
--checkbooleanfalseChecks whether files are already formatted correctly, without modifying them.

Notes

  • Despite the shared flag name, --actions here takes file globs relative to project-dir, not action names. With --ignore-js-files, the default becomes {definitions,includes}/**/*.sqlx.
  • --check exits with code 1 if any file would be reformatted.

Shared project-config flags

compile, test, and run all accept the following flags, which override the equivalent settings in the project's workflow_settings.yaml for that invocation only:

FlagTypeDefaultDescription
--default-databasestring—The default database to use, equivalent to Google Cloud Project ID. If unset, the value from workflow_settings.yaml is used.
--default-schemastring—Override for the default schema name. If unset, the value from workflow_settings.yaml is used.
--default-locationstring—The default location to use. See https://cloud.google.com/bigquery/docs/locations for supported values. If unset, the value from workflow_settings.yaml is used.
--assertion-schemastring—Default assertion schema. If unset, the value from workflow_settings.yaml is used.
--varsstring—Variables to inject, as comma-separated key=value pairs (e.g. --vars=env=staging,region=eu), referenced in code via dataform.projectConfig.vars.<key>. If unset, the value from workflow_settings.yaml is used.
--database-suffixstring—A suffix to be appended to output database names. If unset, the value from workflow_settings.yaml is used.
--schema-suffixstring—A suffix to be appended to output schema names. Must contain only alphanumeric characters and/or underscores. If unset, the value from workflow_settings.yaml is used.
--table-prefixstring—Adds a prefix for all table names. If unset, the value from workflow_settings.yaml is used.
--disable-assertionsbooleanfalseDisables all assertions including built-in assertions (uniqueKey, nonNull, rowConditions) and manual assertions (type: assertion).
--default-reservationstring—The default BigQuery reservation to use for execution. If unset, the value from workflow_settings.yaml is used. If neither is set, default BigQuery behavior applies.

Credentials file

init-creds writes a .df-credentials.json file (filename fixed, not configurable) into the project directory. This file stores the connection details Dataform needs to reach your warehouse:

  • ADC-based: { "projectId": ..., "location": ... }
  • JSON-key-based: { "projectId": ..., "credentials": "<service account key JSON as a string>", "location": ... }

Additional details:

  • Location is optional in both of the above (init-creds omits it if auto is chosen)
  • Service account impersonation (optional, with either of the above): add "impersonateServiceAccount": "<service account email>" to run BigQuery queries (and lineage emission) as that service account. Your ADC identity, or the key above, is used to impersonate it and needs roles/iam.serviceAccountTokenCreator on that service account. init-creds asks for it as an optional last step.

Only BigQuery is supported by init-creds and the bundled BigQuery adapter in this codebase. Treat .df-credentials.json as a secret — dataform init adds it to .gitignore automatically; never commit it.


Example use cases

First-time project setup

dataform init my_project my-gcp-project-id US
cd my_project
dataform init-creds
dataform run

Compiling and inspecting a project without touching the warehouse

# Human-readable summary
dataform compile

# Full compiled graph as JSON, e.g. to pipe into jq
dataform compile --json | jq '.tables[].target'

# Visualize the dependency graph
dataform compile --dot > graph.dot && dot -Tpng graph.dot -o graph.png

# Only show a subset of the graph (by unambiguous action name or full database.schema.name target)
dataform compile --output-actions=my_table --output-include-deps
dataform compile --output-actions=my-gcp-project-id.my_schema.my_table --output-include-deps

Running unit tests before deploying changes

dataform test
# ...or fail a run early if tests don't pass:
dataform run --run-tests

Running only part of a pipeline

# Run a specific table (by bare name or full database.schema.name) and anything downstream of it
dataform run --actions=my_table --include-dependents
dataform run --actions=my-gcp-project-id.my_schema.my_table --include-dependents

# Run everything tagged "daily", including their dependencies
dataform run --tags=daily --include-deps

# Force a full rebuild of the "my_incremental_table" incremental table
dataform run --actions=my_incremental_table --full-refresh

Validating a run without applying changes

dataform run --dry-run --json > dry-run-result.json

Bounding how long a run is allowed to take

# Compilation must finish within 30s; the whole run (compile + execute) within 15 minutes
dataform run --timeout=30s --execution-timeout=15m

# Cap each JiT-compiled model's own compilation step at 1 minute
dataform run --execution-timeout=15m --jit-timeout=1m

Targeting a different environment for one invocation

dataform run \
  --default-database=my-staging-project \
  --schema-suffix=staging \
  --vars=env=staging,region=eu

Iterating on SQLX during development

dataform compile --watch

Checking formatting without modifying files

dataform format --check

Tracking and labeling jobs from a run

dataform run --job-prefix=nightly --job-labels=team=analytics,pipeline=nightly-etl

Emitting lineage events for a run

DATAFORM_LINEAGE_DEBUG=1 dataform run --emit-lineage

Lineage events are emitted for every action that runs a BigQuery job: tables (including views and incremental tables), operations, assertions and property graphs. On COMPLETE events, inputs and outputs are populated for actions that materialize a BigQuery object (table, view, incremental, assertion, propertyGraph, and operations with hasOutput: true). Assertions appear as a process for the assertion view written to the assertions dataset, with the assertion's dependencies reported as inputs. Property graph inputs are populated from the action's dependencies (dependencyTargets), so node and edge tables referenced via ref are reported as inputs while raw table paths in the graph definition are not. Declarations are not emitted. The action type is reported in the gcp_bq_pipelines_job.actionType attribute as TABLE, OPERATIONS, ASSERTION or PROPERTY_GRAPH, matching the values used by Dataform in Google Cloud. For prerequisites, workflow_settings.yaml configuration, and troubleshooting, see the Data Lineage guide.

Lineage events are sent to the location set by defaultLocation in workflow_settings.yaml or, if that is not set, by location in .df-credentials.json. If neither is set, lineage emission is skipped with a warning and the run proceeds normally.

版本与发布记录

@dataform/cli 共发布 321 个版本,首次发布于 2018/09/19;过去 12 个月发布了 41 个版本。

版本发布日期距今
3.1.5latest2026/11/101 天前
3.1.5-alpha.2next2026/11/101 天前
3.1.42026/11/065 天前
3.1.32026/11/029 天前
3.1.22026/10/2121 天前
3.1.12026/10/2022 天前

关于 @dataform/cli 的常见问题

@dataform/cli 是什么?

Dataform command line interface.

如何安装 @dataform/cli?

在项目目录运行 npm install @dataform/cli,或使用 pnpm add / yarn add / bun add。它还提供命令行工具 dataform,可以用 npx dataform 直接运行。

@dataform/cli 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dataform__cli 是否存在。

@dataform/cli 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dataform/cli 可以商用吗?

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

@dataform/cli 的下载量有多少?

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

@dataform/cli 还在维护吗?

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