bqmigrate
BigQuery schema migrations for Python.
Status: alpha. The API may change between 0.x versions.
Works today
- Tables declared in Python. Each table's columns, modes, nested records, partitioning and clustering live in one spec, checked where it is declared, so a spec BigQuery would refuse fails on import.
- Alembic revisions that know BigQuery. In-place changes rendered from the spec (
add_column,drop_column,rename_column,widen_type, defaults and descriptions), each safe to rerun. A change BigQuery cannot make in place, such as adding a REQUIRED column, is refused. - A cost limit on every statement. Each query job is capped at a scan limit and labelled with the run id; a revision raises the limit explicitly, only around the statements that need more.
- A ledger that cannot be rewritten. Every applied revision is recorded with the hash of its file, and a run refuses to start when an applied revision was edited.
- Table rebuilds for what
ALTERcannot do. The table is snapshotted, a copy is written as the spec declares it and checked against the spec and the row count, and only then swapped in. A table whose rows or attributes the rebuild would lose is refused before anything is written, and so is a swap when the table was written during the rebuild. - Drift checks per environment. Each spec is compared with its live table, columns at every depth, description, partitioning and clustering. Drift an environment has accepted is listed, and the check fails on anything else, and on listed drift that is gone.
- A plan for the next revision. Each drift is named with how BigQuery can make it good: in place with a named operation, through a schema update, or by a rebuild, and which tables need rebuilding.
- A command line.
upgrade,pending,driftandplan, each against one environment.
Usage
Declare the tables:
# myapp/schemas.py
from bqmigrate.spec import Column, Dataset, Table
from bqmigrate.types import ColumnType, Mode
EVENTS = Table(
name="events",
columns=(
Column(name="id", type=ColumnType.STRING, mode=Mode.REQUIRED),
Column(name="country", type=ColumnType.STRING),
),
clustering=("id",),
)
ANALYTICS = Dataset(name="analytics", tables=(EVENTS,))
DATASETS = (ANALYTICS,)
Describe the project in bqmigrate.toml:
revisions = "migrations"
datasets = "myapp.schemas:DATASETS"
[environments.staging]
project = "acme-staging"
dataset_prefix = "staging_"
known_drift = "drift/staging.json"
[environments.production]
project = "acme"
migrations/env.py hands Alembic to the run:
from bqmigrate.run import MigrationRun
MigrationRun.current().run_migrations()
A revision in migrations/versions/ states its change in the spec's terms:
from alembic.op import execute
from bqmigrate import operations
from bqmigrate.run import MigrationRun
from myapp.schemas import ANALYTICS, EVENTS
revision = "0002"
down_revision = "0001"
def upgrade() -> None:
events = MigrationRun.current().environment.dataset(ANALYTICS).table(EVENTS)
execute(operations.add_column(events, column=EVENTS.column("country")))
Then, per environment:
bqmigrate plan staging # what differs from the specs, and how to make it good
bqmigrate upgrade staging --release v1.4.0 # apply the pending revisions
bqmigrate drift staging # fail on drift the environment has not accepted
Tests
uv run pytest runs the unit tests. The operations, drift check, rebuild and upgrade also run
against a real BigQuery project when BQMIGRATE_TEST_PROJECT names one the default credentials can
create datasets in:
BQMIGRATE_TEST_PROJECT=my-project uv run pytest tests/test_bigquery_integration.py
Each run creates datasets of its own and deletes them afterwards. The project needs billing enabled: the ledger and Alembic's version table are written with DML, which a sandbox project refuses.
Metadata
Release files for bqmigrate 0.1.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bqmigrate-0.1.2.tar.gz | 120.6 kB | With provenance | Details for bqmigrate-0.1.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bqmigrate-0.1.2-py3-none-any.whl | Python 3 | none | any | Details for bqmigrate-0.1.2-py3-none-any.whl |
Total release size: 161.9 kB
Release files / bqmigrate-0.1.2.tar.gz
| Download URL | bqmigrate-0.1.2.tar.gz |
|---|---|
| Size | 120.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
e3925a56fcf1ea0229ba2af67b274d92043a20bf37617e20b25bf9b2914d7d5d
|
|
BLAKE2b-256 checksum How to use checksums |
f4d146a8fac70cf23c634366cfbbf11c7290e6dda6ff41a9e2da8eb911567177
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logRelease files / bqmigrate-0.1.2-py3-none-any.whl
| Download URL | bqmigrate-0.1.2-py3-none-any.whl |
|---|---|
| Size | 41.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
95168af1abf2c984ba22937da5cfad5b2ca7ae317f10eb2ea7e628b1907d948c
|
|
BLAKE2b-256 checksum How to use checksums |
0f9cfa4d35bd609e3f582bb4bb7579b541237403879ebc68ed5476933ca87caf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logSecurity for bqmigrate 0.1.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for bqmigrate-0.1.2.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Dec 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.