Skip to main content

Local BigQuery

A BigQuery emulator for development and tests. It serves the BigQuery REST and Storage APIs and runs GoogleSQL on DuckDB, so the official clients work with no project or credentials.

Quick start

docker run -p 9050:9050 -p 9060:9060 -v bigquery:/data ghcr.io/novucs/local-bigquery:0.4.0

Then point a client at http://localhost:9050, without credentials. Any project ID works, and data persists in /data.

Connecting

Python

from google.auth.credentials import AnonymousCredentials
from google.cloud import bigquery

client = bigquery.Client(
    project="local",
    credentials=AnonymousCredentials(),
    client_options={"api_endpoint": "http://localhost:9050"},
)
rows = client.query_and_wait("SELECT 1 AS x")

For faster to_dataframe(), add the Storage Read API, served as plain gRPC on port 9060:

import grpc
from google.cloud import bigquery_storage_v1
from google.cloud.bigquery_storage_v1.services.big_query_read.transports import (
    BigQueryReadGrpcTransport,
)

transport = BigQueryReadGrpcTransport(channel=grpc.insecure_channel("localhost:9060"))
bqstorage = bigquery_storage_v1.BigQueryReadClient(transport=transport)
frame = client.query_and_wait("SELECT 1 AS x").to_dataframe(bqstorage_client=bqstorage)

For SQLAlchemy, pass the client in: create_engine("bigquery://local", connect_args={"client": client}).

Go

client, err := bigquery.NewClient(ctx, "local",
    option.WithEndpoint("http://localhost:9050/bigquery/v2/"),
    option.WithoutAuthentication(),
)

Node.js

import { BigQuery } from "@google-cloud/bigquery";

const bigquery = new BigQuery({ projectId: "local", apiEndpoint: "http://localhost:9050" });
const [rows] = await bigquery.query("SELECT 1 AS x");

Testing with pytest

pip install local-bigquery

This adds pytest fixtures that run the emulator inside the test process. There's no Docker, and it starts in under a second:

  • bigquery_client: a client connected to an emulator shared by the whole test run.
  • bigquery_dataset: a new dataset for each test, deleted afterwards.
  • bigquery_emulator: the emulator's rest_url, grpc_address and project_id.
def test_totals(bigquery_client, bigquery_dataset):
    table = f"{bigquery_dataset.dataset_id}.orders"
    bigquery_client.query_and_wait(f"CREATE TABLE {table} (customer STRING, amount INT64)")
    bigquery_client.insert_rows_json(table, [{"customer": "a", "amount": 2}] * 3)
    rows = bigquery_client.query_and_wait(f"SELECT SUM(amount) AS total FROM {table}")
    assert [row.total for row in rows] == [6]

Features

  • SQL: GoogleSQL functions, DML including MERGE, DDL, scripting, procedures, SQL/JavaScript UDFs, table functions, wildcard tables, INFORMATION_SCHEMA.
  • Tables: partitioning, clustering, constraints, views, materialized views, snapshots, clones, time travel, search and vector indexes.
  • Jobs: query, load, copy and extract, with dry runs, cancellation and sessions.
  • Data: CSV, JSON, Parquet, Avro and ORC loads, and CSV, JSON, Parquet and Avro exports. Also insert_rows_json and the Storage Read and Write APIs.
  • gs://: maps to $DATA_DIR/gcs, or to a GCS emulator set by STORAGE_EMULATOR_HOST.
  • Row access policies: the caller is the service account that signed the request. Signatures aren't checked, so any key works: service_account.Credentials.from_service_account_file("key.json", always_use_jwt_access=True). Unsigned requests run as CALLER.
  • EXTERNAL_QUERY against Postgres at POSTGRES_URI.
  • REPL: local-bigquery repl. Delete all data with local-bigquery reset.

Limitations

  • For test-sized data on one machine. There's no authentication, and IAM policies aren't enforced.
  • Legacy SQL and BigQuery ML functions (ML.PREDICT and so on) aren't supported.
  • A failed statement aborts the whole transaction.
  • STRING(n) and BYTES(n) lengths aren't enforced.
  • Other API methods return 501.

Found a difference from BigQuery? Open an issue.

Configuration

Set these as environment variables, or pass the matching flag to local-bigquery.

Variable Flag Default
BIGQUERY_PORT --port 9050
GRPC_PORT --grpc-port 9060
DATA_DIR --data-dir /data
DEFAULT_PROJECT_ID --project local
DEFAULT_DATASET_ID --dataset local
CALLER user:local-bigquery@localhost
GROUPS {}, e.g. {"user:alice@example.com": ["group:team@example.com"]}
GCS_LOCAL_ROOT $DATA_DIR/gcs
STORAGE_EMULATOR_HOST
POSTGRES_CONNECTION_ID us.default
POSTGRES_URI postgresql://postgres:example@db:5432/postgres

Development

uv run local-bigquery --data-dir /tmp/local-bigquery   # run from source
uv run pytest                                           # run the tests
uv run pytest --endpoint google --project <project>     # run them against real BigQuery

License

MIT

Metadata

Release files for local-bigquery 0.4.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for local-bigquery 0.4.0
File Size Uploaded Provenance Actions
local_bigquery-0.4.0.tar.gz 225.3 kB Without provenance Details for local_bigquery-0.4.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for local-bigquery 0.4.0
File Interpreter ABI Platform Actions
local_bigquery-0.4.0-py3-none-any.whl Python 3 none any Details for local_bigquery-0.4.0-py3-none-any.whl

Total release size: 487.8 kB

Release files / local_bigquery-0.4.0.tar.gz

Download URL local_bigquery-0.4.0.tar.gz
Size 225.3 kB
Tags Source
SHA-256 checksum
How to use checksums
f5840496c82bc44eb4f19651dff6c255ac1b2ddc295afd8f849aa5f402e513e1
BLAKE2b-256 checksum
How to use checksums
50b8e72e484ec72bdc9229815d3530631fceac7192d17fb9ee17945a33f019e1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / local_bigquery-0.4.0-py3-none-any.whl

Download URL local_bigquery-0.4.0-py3-none-any.whl
Size 262.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6addd829616f49a06e74b3501b4edba3b1b638fb6b6529583d283deee1f30f50
BLAKE2b-256 checksum
How to use checksums
a56cc395c9ce319771f07a2ae45810abeeafa21430f082accd5887f204498b16
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for local-bigquery 0.4.0

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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page