Migrate BigQuery views into Dataform view definitions.
Project description
dataform-view-migrator
Export BigQuery VIEW SQL definitions into a Dataform project with a predictable layout and safe write policies.
This README focuses on using the tool. For development setup and project conventions, see DEVELOPMENT.md.
📦 PyPI: https://pypi.org/project/dataform-view-migrator/ 💻 GitHub: https://github.com/elvainch/dataform-view-migrator
Prerequisites
- Python 3.10+
- Auth via Application Default Credentials (ADC):
- Set
GOOGLE_APPLICATION_CREDENTIALSto a service account JSON, or - Run
gcloud auth application-default login
- Set
Install
pip install dataform-view-migrator
Commands
dataform-view-migrator(orpython -m dataform_view_migrator): prints quick usage and versiondataform-view-migrator ping-bq [--project <id>] [--location <REGION>] [--config <toml>]- Verifies auth and prints the resolved BigQuery project. If
--locationis provided (or set in TOML), it performs a regional INFORMATION_SCHEMA dry-run; otherwise it lists datasets to verify access.
- Verifies auth and prints the resolved BigQuery project. If
dataform-view-migrator migrate-views [options]- Discovers BigQuery views and writes files into the Dataform repo path.
Run --help on any command for complete options.
Configuration
- Copy
dataform_view_migrator.example.tomltodataform_view_migrator.tomland edit. - CLI flags override TOML values when explicitly provided.
Key options (flag → TOML):
--source-project→source_project(required via config or flag)--dest <path>→dest(required via config or flag)--datasets a,b→datasets_include = ["a","b"]--exclude-datasets x,y→datasets_exclude = ["x","y"]--location US→location = "US"--ext sql|sqlx→ext = "sqlx"(defaultsqlx)--overwrite skip|backup|force→overwrite = "skip"(defaultskip)--add-dataform-header/--no-add-dataform-header→add_dataform_header = true|false--dry-run/--no-dry-run→dry_run = false- Optional dataset folder remapping:
dataset_folders = { src = "src_views" }
Output Layout
- Files are written under
dest/<dataset>/<view_name>.<ext>by default. - Use
dataset_foldersin TOML to map dataset names to custom subfolders. - Extension
extissqlxby default; set--ext sqlfor plain SQL files.
Dataform Header (optional)
When enabled, each file is prefixed with a Dataform config block:
config {
type: "view",
schema: "<dataset>",
name: "<view>"
# optional fields below when configured
# description: "...",
# tags: ["..."]
}
Control via --add-dataform-header (or add_dataform_header = true).
Customize with dataform_header.description and dataform_header.tags in TOML.
Overwrite Policy
skip(default): do not modify existing files; they are reported asskipped.backup: if a file exists, move it to<name>.<ext>.bak[.N]and write the new content.force: overwrite files in place.
All modes support --dry-run to preview actions as would-create, would-update, or would-skip without writing.
Examples
- Verify auth/project using TOML defaults:
uv run dataform-view-migrator ping-bq --config dataform_view_migrator.toml
- Migrate all views to a Dataform repo (US region, backup existing):
uv run dataform-view-migrator migrate-views --source-project my-proj --dest ../dataform --location US --overwrite backup
- Include specific datasets and emit plain SQL:
uv run dataform-view-migrator migrate-views --source-project my-proj --dest ../dataform --datasets sales,finance --ext sql
- Dry-run to review changes only:
uv run dataform-view-migrator migrate-views --config dataform_view_migrator.toml --dry-run
Output Report
After migration, a table of per-view results is printed (dataset, view, action, path, error) followed by a compact summary grouped by action. A non-zero exit code is returned if any views fail.
Development
See DEVELOPMENT.md for environment setup, linting/formatting, tests, and project layout.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file dataform_view_migrator-0.1.5.tar.gz.
File metadata
- Download URL: dataform_view_migrator-0.1.5.tar.gz
- Upload date:
- Size: 51.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cb2da79636eb1718f1bb184736f2ea6bd4d16a9f168add800c306fa7fb661211
|
|
| MD5 |
c68178386b6b7010e461a6bfb1f3d29d
|
|
| BLAKE2b-256 |
7c611337e0268c7732f9351350bcae5e135551f40cb0be525a67802fb241107f
|
File details
Details for the file dataform_view_migrator-0.1.5-py3-none-any.whl.
File metadata
- Download URL: dataform_view_migrator-0.1.5-py3-none-any.whl
- Upload date:
- Size: 13.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe0d2d45728e9bba6a457383d4320189596e17edf6c40f67a76f7228487ae749
|
|
| MD5 |
3b79ea614616def961dba5b38d2d2dba
|
|
| BLAKE2b-256 |
1b5861d42fd19ed0abb778a66b4ff09ad55c000a9fad5cf67a981b2a50127df1
|