Migrate BigQuery views into Dataform view definitions.
Project description
🚚 dataform-view-migrator
Export BigQuery VIEW definitions into Dataform with ease. 🚀
dataform-view-migrator is a handy CLI tool that discovers your BigQuery views and turns them into Dataform-ready .sqlx or .sql files. It handles complex folder structures, provides safe backup policies, and automatically generates Dataform configuration headers.
⚡ Super Quickstart
-
Install
pip install dataform-view-migrator
-
Authenticate
gcloud auth application-default login
-
Migrate!
dataform-view-migrator migrate-views --source-project my-project --dest ./my-dataform-repo
💡 Example Input & Output
BigQuery View (my_project.my_dataset.daily_sales):
SELECT date, SUM(amount) as total_sales
FROM `my_project.my_dataset.raw_transactions`
GROUP BY 1
Generated Dataform File (my-dataform-repo/my_dataset/daily_sales.sqlx):
config {
type: "view",
schema: "my_dataset",
name: "daily_sales",
description: "CREATED BY DATAFORM.",
tags: ["my-tag","another-tag"],
}
SELECT date, SUM(amount) as total_sales
FROM `my_project.my_dataset.raw_transactions`
GROUP BY 1
✨ Features
- 🔍 Auto-discovery: Find all views across multiple datasets automatically.
- 📂 Flexible Layout: Map BigQuery datasets to custom subfolders in your Dataform project.
- 🛡️ Safe Writes: Choose to
skip,backup, orforceoverwrite existing files. - 📝 Dataform Headers: Automatically adds
config { type: "view", ... }to your.sqlxfiles. - 🧪 Dry Run: Preview exactly what will happen before making any changes.
- 🚀 Fast: Uses
INFORMATION_SCHEMAfor high-performance discovery in large projects.
🛠 Prerequisites
- Python 3.10+
- GCP Authentication via Application Default Credentials (ADC).
📖 Commands
ping-bq: 📡 Verify your authentication and BigQuery access.dataform-view-migrator ping-bq --project my-project
migrate-views: 🚜 The main event. Discovers and exports views.dataform-view-migrator migrate-views [options]
Run --help on any command for a full list of available options.
⚙️ Configuration
While you can use CLI flags, using a TOML file is often easier for recurring tasks. Copy dataform_view_migrator.example.toml to dataform_view_migrator.toml and customize it.
Available Keys
| Key | Type | Default | Description |
|---|---|---|---|
source_project |
string |
Required. The GCP project ID containing your views. | |
dest |
string |
Required. Local path to your Dataform repository. | |
datasets_include |
list |
[] |
List of datasets to process. If empty, processes all. |
datasets_exclude |
list |
[] |
List of datasets to ignore. |
location |
string |
BigQuery region (e.g., US, EU). Required for high-performance discovery. |
|
ext |
string |
sqlx |
File extension: sqlx or sql. |
overwrite |
string |
skip |
Policy: skip, backup (renames existing), or force. |
add_dataform_header |
boolean |
true |
Prepend config {} block to files. |
dry_run |
boolean |
false |
If true, only show what would happen. |
dataform_header.description |
string |
Optional description for the Dataform config block. | |
dataform_header.tags |
list |
[] |
Optional list of tags for the Dataform config block. |
dataset_folders |
dict |
Map dataset IDs to custom subfolders (e.g., ds_id = "path/to/dir"). |
📂 Output Layout
By default, files are saved as dest/<dataset>/<view_name>.sqlx.
You can remap dataset names to specific folders using the dataset_folders setting in your config:
[dataset_folders]
raw_data = "sources/raw"
analytics = "definitions/reporting"
🤝 Contributing & Development
We love contributions! Please check out DEVELOPMENT.md for setup instructions, linting rules, and testing guidelines.
🔗 Links
- 📦 PyPI: https://pypi.org/project/dataform-view-migrator/
- 💻 GitHub: https://github.com/elvainch/dataform-view-migrator
- 📝 License: MIT
Developed by Alan Vainsencher.
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.6.tar.gz.
File metadata
- Download URL: dataform_view_migrator-0.1.6.tar.gz
- Upload date:
- Size: 51.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
56fe3af50a6b2fd0282eebfa818b442a845494c91647e54b868efba2c081b4ce
|
|
| MD5 |
4060a1a35334bce2a30e6c863432b48b
|
|
| BLAKE2b-256 |
62aa3edef74c61b38ecf15887701ce6153b1ce242211fe5f512ee777130ac8b7
|
File details
Details for the file dataform_view_migrator-0.1.6-py3-none-any.whl.
File metadata
- Download URL: dataform_view_migrator-0.1.6-py3-none-any.whl
- Upload date:
- Size: 13.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
55a9121ad1a1615f1efb6372437c48b9add0bf759f93b338531477d2e5c7c937
|
|
| MD5 |
f8073eb076279d39e8a29d46703f4820
|
|
| BLAKE2b-256 |
372a919683fe2f767a0768edec157ebbe8989e4b4af6839b6f84621725f822dc
|