Metadata-Version: 2.4
Name: bqemulator
Version: 1.1.2
Summary: Local emulator for Google BigQuery — REST + gRPC (Storage Read/Write) APIs, DuckDB-backed, SQLGlot-powered.
Project-URL: Homepage, https://github.com/jjviscomi/bqemulator
Project-URL: Documentation, https://jjviscomi.github.io/bqemulator/
Project-URL: Repository, https://github.com/jjviscomi/bqemulator
Project-URL: Issues, https://github.com/jjviscomi/bqemulator/issues
Project-URL: Changelog, https://github.com/jjviscomi/bqemulator/blob/main/CHANGELOG.md
Author: bqemulator contributors
License:                                  Apache License
                                   Version 2.0, January 2004
                                http://www.apache.org/licenses/
        
           TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
        
           1. Definitions.
        
              "License" shall mean the terms and conditions for use, reproduction,
              and distribution as defined by Sections 1 through 9 of this document.
        
              "Licensor" shall mean the copyright owner or entity authorized by
              the copyright owner that is granting the License.
        
              "Legal Entity" shall mean the union of the acting entity and all
              other entities that control, are controlled by, or are under common
              control with that entity. For the purposes of this definition,
              "control" means (i) the power, direct or indirect, to cause the
              direction or management of such entity, whether by contract or
              otherwise, or (ii) ownership of fifty percent (50%) or more of the
              outstanding shares, or (iii) beneficial ownership of such entity.
        
              "You" (or "Your") shall mean an individual or Legal Entity
              exercising permissions granted by this License.
        
              "Source" form shall mean the preferred form for making modifications,
              including but not limited to software source code, documentation
              source, and configuration files.
        
              "Object" form shall mean any form resulting from mechanical
              transformation or translation of a Source form, including but
              not limited to compiled object code, generated documentation,
              and conversions to other media types.
        
              "Work" shall mean the work of authorship, whether in Source or
              Object form, made available under the License, as indicated by a
              copyright notice that is included in or attached to the work
              (an example is provided in the Appendix below).
        
              "Derivative Works" shall mean any work, whether in Source or Object
              form, that is based on (or derived from) the Work and for which the
              editorial revisions, annotations, elaborations, or other modifications
              represent, as a whole, an original work of authorship. For the purposes
              of this License, Derivative Works shall not include works that remain
              separable from, or merely link (or bind by name) to the interfaces of,
              the Work and Derivative Works thereof.
        
              "Contribution" shall mean any work of authorship, including
              the original version of the Work and any modifications or additions
              to that Work or Derivative Works thereof, that is intentionally
              submitted to Licensor for inclusion in the Work by the copyright owner
              or by an individual or Legal Entity authorized to submit on behalf of
              the copyright owner. For the purposes of this definition, "submitted"
              means any form of electronic, verbal, or written communication sent
              to the Licensor or its representatives, including but not limited to
              communication on electronic mailing lists, source code control systems,
              and issue tracking systems that are managed by, or on behalf of, the
              Licensor for the purpose of discussing and improving the Work, but
              excluding communication that is conspicuously marked or otherwise
              designated in writing by the copyright owner as "Not a Contribution."
        
              "Contributor" shall mean Licensor and any individual or Legal Entity
              on behalf of whom a Contribution has been received by Licensor and
              subsequently incorporated within the Work.
        
           2. Grant of Copyright License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              copyright license to reproduce, prepare Derivative Works of,
              publicly display, publicly perform, sublicense, and distribute the
              Work and such Derivative Works in Source or Object form.
        
           3. Grant of Patent License. Subject to the terms and conditions of
              this License, each Contributor hereby grants to You a perpetual,
              worldwide, non-exclusive, no-charge, royalty-free, irrevocable
              (except as stated in this section) patent license to make, have made,
              use, offer to sell, sell, import, and otherwise transfer the Work,
              where such license applies only to those patent claims licensable
              by such Contributor that are necessarily infringed by their
              Contribution(s) alone or by combination of their Contribution(s)
              with the Work to which such Contribution(s) was submitted. If You
              institute patent litigation against any entity (including a
              cross-claim or counterclaim in a lawsuit) alleging that the Work
              or a Contribution incorporated within the Work constitutes direct
              or contributory patent infringement, then any patent licenses
              granted to You under this License for that Work shall terminate
              as of the date such litigation is filed.
        
           4. Redistribution. You may reproduce and distribute copies of the
              Work or Derivative Works thereof in any medium, with or without
              modifications, and in Source or Object form, provided that You
              meet the following conditions:
        
              (a) You must give any other recipients of the Work or
                  Derivative Works a copy of this License; and
        
              (b) You must cause any modified files to carry prominent notices
                  stating that You changed the files; and
        
              (c) You must retain, in the Source form of any Derivative Works
                  that You distribute, all copyright, patent, trademark, and
                  attribution notices from the Source form of the Work,
                  excluding those notices that do not pertain to any part of
                  the Derivative Works; and
        
              (d) If the Work includes a "NOTICE" text file as part of its
                  distribution, then any Derivative Works that You distribute must
                  include a readable copy of the attribution notices contained
                  within such NOTICE file, excluding those notices that do not
                  pertain to any part of the Derivative Works, in at least one
                  of the following places: within a NOTICE text file distributed
                  as part of the Derivative Works; within the Source form or
                  documentation, if provided along with the Derivative Works; or,
                  within a display generated by the Derivative Works, if and
                  wherever such third-party notices normally appear. The contents
                  of the NOTICE file are for informational purposes only and
                  do not modify the License. You may add Your own attribution
                  notices within Derivative Works that You distribute, alongside
                  or as an addendum to the NOTICE text from the Work, provided
                  that such additional attribution notices cannot be construed
                  as modifying the License.
        
              You may add Your own copyright statement to Your modifications and
              may provide additional or different license terms and conditions
              for use, reproduction, or distribution of Your modifications, or
              for any such Derivative Works as a whole, provided Your use,
              reproduction, and distribution of the Work otherwise complies with
              the conditions stated in this License.
        
           5. Submission of Contributions. Unless You explicitly state otherwise,
              any Contribution intentionally submitted for inclusion in the Work
              by You to the Licensor shall be under the terms and conditions of
              this License, without any additional terms or conditions.
              Notwithstanding the above, nothing herein shall supersede or modify
              the terms of any separate license agreement you may have executed
              with Licensor regarding such Contributions.
        
           6. Trademarks. This License does not grant permission to use the trade
              names, trademarks, service marks, or product names of the Licensor,
              except as required for describing the origin of the Work and
              reproducing the content of the NOTICE file.
        
           7. Disclaimer of Warranty. Unless required by applicable law or
              agreed to in writing, Licensor provides the Work (and each
              Contributor provides its Contributions) on an "AS IS" BASIS,
              WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
              implied, including, without limitation, any warranties or conditions
              of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
              PARTICULAR PURPOSE. You are solely responsible for determining the
              appropriateness of using or redistributing the Work and assume any
              risks associated with Your exercise of permissions under this License.
        
           8. Limitation of Liability. In no event and under no legal theory,
              whether in tort (including negligence), contract, or otherwise,
              unless required by applicable law (such as deliberate and grossly
              negligent acts) or agreed to in writing, shall any Contributor be
              liable to You for damages, including any direct, indirect, special,
              incidental, or consequential damages of any character arising as a
              result of this License or out of the use or inability to use the
              Work (including but not limited to damages for loss of goodwill,
              work stoppage, computer failure or malfunction, or any and all
              other commercial damages or losses), even if such Contributor
              has been advised of the possibility of such damages.
        
           9. Accepting Warranty or Additional Liability. While redistributing
              the Work or Derivative Works thereof, You may accept for a fee,
              acceptance of warranty or additional liability, in accordance with
              this License. Nevertheless, in accepting such obligations, You may
              act only on Your own behalf and on Your sole responsibility, not on
              behalf of any other Contributor, and only if You agree to indemnify,
              defend, and hold each Contributor harmless for any liability
              incurred by, or claims asserted against, such Contributor by reason
              of your accepting any such warranty or additional liability.
        
           END OF TERMS AND CONDITIONS
        
           APPENDIX: How to apply the Apache License to your work.
        
              To apply the Apache License to your work, attach the following
              boilerplate notice, with the fields enclosed by brackets "[]"
              replaced with your own identifying information. (Don't include
              the brackets!)  The text should be enclosed in the appropriate
              comment syntax for the file format. We also recommend that a
              file or class name and description of purpose be included on the
              same "printed" page as the copyright notice for easier
              identification within third-party archives.
        
           Copyright 2026 bqemulator contributors
        
           Licensed under the Apache License, Version 2.0 (the "License");
           you may not use this file except in compliance with the License.
           You may obtain a copy of the License at
        
               http://www.apache.org/licenses/LICENSE-2.0
        
           Unless required by applicable law or agreed to in writing, software
           distributed under the License is distributed on an "AS IS" BASIS,
           WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
           See the License for the specific language governing permissions and
           limitations under the License.
License-File: LICENSE
Keywords: bigquery,ci,duckdb,emulator,google-cloud,local,mock,sqlglot,testing
Classifier: Development Status :: 5 - Production/Stable
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: Apache Software License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Database
Classifier: Topic :: Software Development :: Testing
Classifier: Topic :: Software Development :: Testing :: Mocking
Classifier: Typing :: Typed
Requires-Python: >=3.11
Requires-Dist: alembic>=1.13
Requires-Dist: click>=8.1
Requires-Dist: cryptography>=46.0.7
Requires-Dist: duckdb>=1.0
Requires-Dist: fastapi!=0.136.3,>=0.110
Requires-Dist: fastavro>=1.9
Requires-Dist: google-cloud-bigquery-storage>=2.24
Requires-Dist: googleapis-common-protos>=1.62
Requires-Dist: grpcio-health-checking>=1.60
Requires-Dist: grpcio-tools>=1.60
Requires-Dist: grpcio>=1.60
Requires-Dist: httpx>=0.27
Requires-Dist: mako>=1.3.12
Requires-Dist: opentelemetry-api>=1.24
Requires-Dist: opentelemetry-exporter-otlp>=1.24
Requires-Dist: opentelemetry-instrumentation-fastapi>=0.45b0
Requires-Dist: opentelemetry-instrumentation-grpc>=0.45b0
Requires-Dist: opentelemetry-sdk>=1.24
Requires-Dist: orjson>=3.10
Requires-Dist: prometheus-client>=0.20
Requires-Dist: protobuf>=4.25
Requires-Dist: pyarrow>=14.0
Requires-Dist: pyasn1>=0.6.3
Requires-Dist: pydantic-settings>=2.2
Requires-Dist: pydantic>=2.5
Requires-Dist: pyjwt>=2.12.0
Requires-Dist: python-dotenv>=1.2.2
Requires-Dist: pytz>=2024.1
Requires-Dist: requests>=2.33.0
Requires-Dist: sqlglot>=23.0
Requires-Dist: starlette<1.0,>=0.46
Requires-Dist: structlog>=24.1
Requires-Dist: urllib3>=2.7.0
Requires-Dist: uvicorn[standard]>=0.27
Provides-Extra: all
Requires-Dist: fastavro>=1.9; extra == 'all'
Requires-Dist: google-cloud-bigquery>=3.0; extra == 'all'
Requires-Dist: mini-racer>=0.12; extra == 'all'
Requires-Dist: numpy>=1.26; extra == 'all'
Requires-Dist: pyorc>=0.10; extra == 'all'
Requires-Dist: python-snappy>=0.7; extra == 'all'
Requires-Dist: zstandard>=0.22; extra == 'all'
Provides-Extra: avro
Requires-Dist: fastavro>=1.9; extra == 'avro'
Provides-Extra: compression
Requires-Dist: python-snappy>=0.7; extra == 'compression'
Requires-Dist: zstandard>=0.22; extra == 'compression'
Provides-Extra: dev
Requires-Dist: bandit>=1.7; extra == 'dev'
Requires-Dist: diff-cover>=9.0; extra == 'dev'
Requires-Dist: fastavro>=1.9; extra == 'dev'
Requires-Dist: google-cloud-bigquery-storage>=2.24; extra == 'dev'
Requires-Dist: google-cloud-bigquery>=3.0; extra == 'dev'
Requires-Dist: hypothesis>=6.98; extra == 'dev'
Requires-Dist: interrogate>=1.5; extra == 'dev'
Requires-Dist: mike>=2.0; extra == 'dev'
Requires-Dist: mini-racer>=0.12; extra == 'dev'
Requires-Dist: mkdocs-material>=9.5; extra == 'dev'
Requires-Dist: mkdocs>=1.5; extra == 'dev'
Requires-Dist: mkdocstrings[python]>=0.24; extra == 'dev'
Requires-Dist: mutmut>=2.4; extra == 'dev'
Requires-Dist: mypy>=1.9; extra == 'dev'
Requires-Dist: numpy>=1.26; extra == 'dev'
Requires-Dist: pip-audit>=2.7; extra == 'dev'
Requires-Dist: pre-commit>=3.6; extra == 'dev'
Requires-Dist: pygments>=2.20.0; extra == 'dev'
Requires-Dist: pymdown-extensions>=10.21.3; extra == 'dev'
Requires-Dist: pyorc>=0.10; extra == 'dev'
Requires-Dist: pytest-asyncio>=0.23; extra == 'dev'
Requires-Dist: pytest-benchmark>=4.0; extra == 'dev'
Requires-Dist: pytest-cov>=5.0; extra == 'dev'
Requires-Dist: pytest-timeout>=2.3; extra == 'dev'
Requires-Dist: pytest-xdist>=3.5; extra == 'dev'
Requires-Dist: pytest>=9.0.3; extra == 'dev'
Requires-Dist: python-snappy>=0.7; extra == 'dev'
Requires-Dist: radon>=6.0; extra == 'dev'
Requires-Dist: ruff>=0.3; extra == 'dev'
Requires-Dist: testcontainers>=4.0; extra == 'dev'
Requires-Dist: vulture>=2.11; extra == 'dev'
Requires-Dist: xenon>=0.9; extra == 'dev'
Requires-Dist: zstandard>=0.22; extra == 'dev'
Provides-Extra: docs
Requires-Dist: mike>=2.0; extra == 'docs'
Requires-Dist: mkdocs-material>=9.5; extra == 'docs'
Requires-Dist: mkdocs>=1.5; extra == 'docs'
Requires-Dist: mkdocstrings[python]>=0.24; extra == 'docs'
Requires-Dist: pygments>=2.20.0; extra == 'docs'
Requires-Dist: pymdown-extensions>=10.21.3; extra == 'docs'
Provides-Extra: import
Requires-Dist: google-cloud-bigquery>=3.0; extra == 'import'
Provides-Extra: orc
Requires-Dist: pyorc>=0.10; extra == 'orc'
Provides-Extra: testing
Requires-Dist: google-cloud-bigquery-storage>=2.24; extra == 'testing'
Requires-Dist: google-cloud-bigquery>=3.0; extra == 'testing'
Requires-Dist: hypothesis>=6.98; extra == 'testing'
Requires-Dist: pytest-asyncio>=0.23; extra == 'testing'
Requires-Dist: pytest-benchmark>=4.0; extra == 'testing'
Requires-Dist: pytest-cov>=5.0; extra == 'testing'
Requires-Dist: pytest-timeout>=2.3; extra == 'testing'
Requires-Dist: pytest-xdist>=3.5; extra == 'testing'
Requires-Dist: pytest>=9.0.3; extra == 'testing'
Requires-Dist: testcontainers>=4.0; extra == 'testing'
Provides-Extra: udf-js
Requires-Dist: mini-racer>=0.12; extra == 'udf-js'
Requires-Dist: numpy>=1.26; extra == 'udf-js'
Description-Content-Type: text/markdown

<div align="center">

# bqemulator

**A local, drop-in emulator for Google BigQuery.**

DuckDB-backed, SQLGlot-powered, and tested against the real service. Point the official Google Cloud client libraries at it and run your BigQuery code on your laptop or in CI — no real project, no billing, no network.

[![CI](https://github.com/jjviscomi/bqemulator/actions/workflows/ci.yml/badge.svg)](https://github.com/jjviscomi/bqemulator/actions/workflows/ci.yml)
[![E2E](https://github.com/jjviscomi/bqemulator/actions/workflows/e2e.yml/badge.svg)](https://github.com/jjviscomi/bqemulator/actions/workflows/e2e.yml)
[![Conformance](https://github.com/jjviscomi/bqemulator/actions/workflows/conformance.yml/badge.svg)](https://github.com/jjviscomi/bqemulator/actions/workflows/conformance.yml)
[![Docs](https://github.com/jjviscomi/bqemulator/actions/workflows/docs.yml/badge.svg)](https://jjviscomi.github.io/bqemulator/)
[![PyPI](https://img.shields.io/pypi/v/bqemulator.svg?cacheSeconds=120&v=1.1.2)](https://pypi.org/project/bqemulator/)
[![Python](https://img.shields.io/pypi/pyversions/bqemulator.svg?cacheSeconds=120&v=1.1.2)](https://pypi.org/project/bqemulator/)
[![OpenSSF Scorecard](https://api.securityscorecards.dev/projects/github.com/jjviscomi/bqemulator/badge?v=1.1.2)](https://scorecard.dev/viewer/?uri=github.com/jjviscomi/bqemulator)
[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](LICENSE)
[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)
[![Checked with mypy](https://www.mypy-lang.org/static/mypy_badge.svg)](https://mypy-lang.org/)

[**Documentation**](https://jjviscomi.github.io/bqemulator/)
 · [**Quickstart**](https://jjviscomi.github.io/bqemulator/latest/getting-started/)
 · [**Examples**](docs/examples/)
 · [**Compatibility matrix**](https://jjviscomi.github.io/bqemulator/latest/reference/compatibility-matrix/)
 · [**Changelog**](CHANGELOG.md)

</div>

---

## Why bqemulator?

Testing code against real BigQuery is **slow** (network + service latency), **expensive** (every query is billable), and **dangerous** (no rollback in shared environments). The alternatives — mocks, fakes, and shared sandboxes — drift from the real service the moment you stop chasing them.

`bqemulator` is a process you can run locally that **speaks BigQuery's actual wire protocol** (REST + gRPC), backs onto a real analytical SQL engine (DuckDB), and translates GoogleSQL → DuckDB SQL with a rule-based, ADR-grounded translator (SQLGlot). The official `google-cloud-bigquery`, `@google-cloud/bigquery`, `cloud.google.com/go/bigquery`, `com.google.cloud:google-cloud-bigquery`, and `bq` CLI clients all work against it unchanged — only the endpoint differs.

Three use cases, one binary:

- **Ephemeral CI fixture** — `pytest` plugin starts an in-process emulator on a random port; `pip install bqemulator[testing]` is all the wiring you need.
- **Long-running local dev server** — `bqemulator start --data-dir ~/bqemu` persists state across runs; works with the official `bq` CLI, dbt, Airflow, PySpark, Beam, Scio.
- **Offline replica of a real project** — `bqemulator import --from-project <id>` clones schema (and optionally data) from real BigQuery into a local data directory.

## Highlights

- 🟢 **Full REST + gRPC API parity** — Datasets, Tables, Jobs, TableData, Routines, Row Access Policies, Authorized Views, plus Models CRUD metadata. Storage Read API (Arrow and Avro). Storage Write API (all four stream types — `DEFAULT`, `COMMITTED`, `PENDING`, `BUFFERED` — with both proto and Arrow row formats).
- ⚡ **Real SQL** — GoogleSQL translated to DuckDB SQL via 93 SQLGlot rules + 24 rewriters; covers date/time, string, array, struct, range, geography, JSON, approximate-aggregate, statistical, regex, civil-time, and bit operations.
- 🧠 **Features `goccy/bigquery-emulator` doesn't have** — JavaScript UDFs (embedded V8 via `mini-racer`), procedural scripting (`DECLARE` / `BEGIN…END` / `IF` / `LOOP` / `EXCEPTION` / `BEGIN TRANSACTION`), time travel (`FOR SYSTEM_TIME AS OF`), table snapshots, table clones, materialized views with refresh dispatch, GEOGRAPHY (planar via DuckDB-spatial + S2 helpers), RANGE, INTERVAL, authorized views, row-access policies, `INFORMATION_SCHEMA`.
- 🔌 **Five-client e2e matrix** — every release is exercised against the official Python, Node.js, Go, and Java BigQuery client libraries plus Google's `bq` CLI in a live Docker container.
- 🧪 **7-tier test pyramid** — unit + property + integration + conformance + e2e + perf + chaos, plus mutation / fuzz / differential siblings. Combined coverage is gated at ≥90% line + branch.
- 📐 **Conformance corpus** — 1,244 fixtures recorded against real BigQuery. Drift between the emulator and the real service surfaces as a failing test; documented divergences are pinned with ADR references.
- 🐍 **Native pytest plugin** — `pip install bqemulator` registers a pytest plugin; the `bqemu_server` fixture starts an ephemeral in-process emulator on random free ports and sets `BIGQUERY_EMULATOR_HOST`. No `conftest.py` wiring required.
- 🐳 **Multi-arch container** — `ghcr.io/jjviscomi/bqemulator` builds for `linux/amd64` + `linux/arm64`, with cosign keyless signatures via GitHub OIDC.
- 🔭 **Production-grade observability** — `structlog` JSON logs, OpenTelemetry tracing (configurable OTLP exporter), Prometheus metrics endpoint.

## Install

```bash
pip install bqemulator
```

Optional extras:

```bash
pip install "bqemulator[testing]"      # pytest, hypothesis, testcontainers, bigquery client
pip install "bqemulator[udf-js]"       # JavaScript UDF support (embedded V8)
pip install "bqemulator[orc]"          # ORC format for load jobs
pip install "bqemulator[compression]"  # zstd + snappy for load/extract jobs
pip install "bqemulator[import]"       # bqemulator import --from-project
pip install "bqemulator[all]"          # all runtime extras (no testing extras)
```

Docker:

```bash
docker run --rm -p 9050:9050 -p 9060:9060 ghcr.io/jjviscomi/bqemulator:latest
```

Both `pip` and the published image bundle the same emulator. The image exposes REST on `9050` and gRPC on `9060` by default — see [configuration reference](https://jjviscomi.github.io/bqemulator/latest/reference/configuration/) to change them.

> **Windows users:** install [Docker Desktop for Windows](https://www.docker.com/products/docker-desktop/) with the WSL2 backend (default since Docker Desktop 4.x); the published Linux image runs natively under WSL2 with no Windows-specific configuration. Native Windows-container variants of the image are explicitly out of scope for v1.0 — see [docs/reference/out-of-scope.md#native-windows-containers](docs/reference/out-of-scope.md) for the rationale.

## Quickstart

### Python

```python
import os
from google.cloud import bigquery

# Either set BIGQUERY_EMULATOR_HOST (picked up by every Google Cloud library)
# or pass api_endpoint explicitly to the Client. Both work.
os.environ["BIGQUERY_EMULATOR_HOST"] = "localhost:9050"

client = bigquery.Client(project="my-test-project")

client.create_dataset("sales")
client.create_table(
    bigquery.Table(
        "sales.orders",
        schema=[
            bigquery.SchemaField("id", "INT64"),
            bigquery.SchemaField("amount", "NUMERIC"),
            bigquery.SchemaField("placed_at", "TIMESTAMP"),
        ],
    )
)
client.insert_rows_json(
    "sales.orders",
    [{"id": 1, "amount": "12.50", "placed_at": "2026-05-21T00:00:00Z"}],
)

for row in client.query("SELECT COUNT(*) AS n FROM sales.orders").result():
    print(row.n)  # 1
```

### pytest

`bqemulator` ships a pytest plugin via the `pytest11` entry point. Installing the package is all the wiring you need — your `conftest.py` stays empty.

```python
from google.cloud import bigquery

def test_orders_table(bqemu_client: bigquery.Client) -> None:
    bqemu_client.create_dataset("sales")
    # ... your test ...
```

The `bqemu_server` fixture is session-scoped (one emulator per test session); the `bqemu_client` fixture is function-scoped and returns a pre-configured `bigquery.Client`. See the [pytest fixture guide](https://jjviscomi.github.io/bqemulator/latest/quickstart/pytest/) and the [`python/pytest-integration`](docs/examples/python/pytest-integration/) example for a complete Flask app with integration tests.

### Node.js

```javascript
const { BigQuery } = require('@google-cloud/bigquery');

const bq = new BigQuery({
  projectId: 'my-test-project',
  apiEndpoint: 'http://localhost:9050',
  token: 'dummy',  // emulator accepts any token
});

await bq.createDataset('sales');
```

See the [Node.js quickstart](https://jjviscomi.github.io/bqemulator/latest/quickstart/nodejs/) and the [`nodejs/nestjs-app`](docs/examples/nodejs/nestjs-app/) example.

### Go

```go
client, _ := bigquery.NewClient(
    ctx, "my-test-project",
    option.WithEndpoint("http://localhost:9050"),
    option.WithoutAuthentication(),
)
```

See the [Go quickstart](https://jjviscomi.github.io/bqemulator/latest/quickstart/go/) and the [`go/beam-pipeline`](docs/examples/go/beam-pipeline/) example.

### Java

```java
BigQuery bq = BigQueryOptions.newBuilder()
    .setProjectId("my-test-project")
    .setHost("http://localhost:9050")
    .setCredentials(NoCredentials.getInstance())
    .build()
    .getService();
```

See the [Java quickstart](https://jjviscomi.github.io/bqemulator/latest/quickstart/java/) and the [`java/spring-boot`](docs/examples/java/spring-boot/) example.

### `bq` CLI

```bash
bq --api=http://localhost:9050 \
   --project_id=my-test-project \
   query --use_legacy_sql=false 'SELECT 1 AS n'
```

See the [`bq` CLI guide](https://jjviscomi.github.io/bqemulator/latest/guides/using-bq-cli/) and the [`bq-cli-quickstart`](docs/examples/bq-cli-quickstart/) example.

### docker-compose

```yaml
services:
  bqemulator:
    image: ghcr.io/jjviscomi/bqemulator:latest
    ports: ["9050:9050", "9060:9060"]
    healthcheck:
      test: ["CMD", "curl", "-sf", "http://localhost:9050/healthz"]
      interval: 2s
      retries: 30

  app:
    build: .
    environment:
      BIGQUERY_EMULATOR_HOST: bqemulator:9050
    depends_on:
      bqemulator: { condition: service_healthy }
```

See the [`docker-compose/full-stack`](docs/examples/docker-compose/full-stack/) example for app + emulator + Prometheus + Grafana.

## What works today

`bqemulator` is at **v1.1.2** — first minor on the production-stable
line. SemVer applies: breaking changes ship only in MAJOR,
deprecations live ≥2 MINOR or 6 months. The [compatibility matrix](https://jjviscomi.github.io/bqemulator/latest/reference/compatibility-matrix/) is auto-generated from the conformance corpus on every CI run; the [conformance coverage matrix](https://jjviscomi.github.io/bqemulator/latest/reference/conformance-coverage-matrix/) breaks down support by surface item.

| Surface | Status |
|---|---|
| BigQuery REST: Datasets / Tables / Jobs / TableData / Routines / Row Access Policies / Authorized Views | ✅ |
| Multipart + resumable upload (`/upload/bigquery/v2/...`) | ✅ |
| `INFORMATION_SCHEMA` (TABLES, COLUMNS, ROUTINES, VIEWS, JOBS, JOBS_BY_*, MATERIALIZED_VIEWS, PARTITIONS, TABLE_OPTIONS, …) | ✅ |
| Storage Read API (Arrow + Avro) | ✅ |
| Storage Write API (all 4 stream types, proto + Arrow row formats) | ✅ |
| GoogleSQL function surface (date / time / string / array / struct / JSON / regex / aggregate / approx / civil-time / bit) | ✅ |
| Procedural scripting (`DECLARE`, `BEGIN…END`, `IF`, `LOOP`, `EXCEPTION`, `BEGIN TRANSACTION`) | ✅ |
| SQL / JavaScript / Table-valued UDFs | ✅ |
| Time travel (`FOR SYSTEM_TIME AS OF`), snapshots, clones, materialized views | ✅ |
| Authorized views + row access policies + caller identity | ✅ |
| GEOGRAPHY / RANGE / INTERVAL / NUMERIC / BIGNUMERIC types | ✅ |
| Load formats: CSV / JSON / Avro / ORC / Parquet | ✅ |
| Extract formats: CSV / JSON / Avro / Parquet | ✅ |
| BigQuery ML (`CREATE MODEL`, `ML.PREDICT`, …) | ❌ Out of scope — see [`docs/reference/out-of-scope.md`](docs/reference/out-of-scope.md) |
| BI Engine / slot reservations / Data Transfer Service / scheduled queries | ❌ Out of scope |

**Conformance corpus depth** (the [conformance coverage matrix](https://jjviscomi.github.io/bqemulator/latest/reference/conformance-coverage-matrix/) carries the live, auto-generated breakdown):

| Status | Surface items | % of deterministic surface |
|---|---|---|
| 🟢🟢 Deep (≥6 fixtures) | 98 | 24.3% |
| 🟢 Covered (3–5 fixtures) | 69 | 17.1% |
| 🟡 Sampled (1–2 fixtures) | 235 | 58.3% |
| 🔴 Uncovered (0 fixtures) | 1 | 0.2% |
| **Total** | **403** | 100.0% |

Plus **10 non-deterministic items** (`RAND`, `CURRENT_*`, `SESSION_USER`, `GENERATE_UUID`, `TABLESAMPLE`, `FOR SYSTEM_TIME AS OF <expression>`) that are excluded from the conformance corpus by [ADR 0022](docs/adr/0022-conformance-corpus-design.md) and exercised in unit / property / integration tiers instead — bringing the full inventory to **413 surface items across 20 categories**, backed by a **1,244-fixture conformance corpus** (1,170 SQL + 48 HTTP + 26 gRPC) under `tests/conformance/`.

We follow a **no-deferral principle**: features either ship complete or are excluded with documented rationale. There is no "TODO for v1.1." Scope boundaries are catalogued in [`docs/reference/out-of-scope.md`](docs/reference/out-of-scope.md).

## Documentation

The full documentation lives at **[jjviscomi.github.io/bqemulator](https://jjviscomi.github.io/bqemulator/)**. Key entry points:

- [**Getting started**](https://jjviscomi.github.io/bqemulator/latest/getting-started/) — your first ten minutes.
- [**Per-language quickstarts**](https://jjviscomi.github.io/bqemulator/latest/quickstart/python/) — Python · Node.js · Go · Java · pytest · docker-compose · Testcontainers.
- [**Guides**](https://jjviscomi.github.io/bqemulator/latest/guides/loading-data/) — loading data, querying, streaming inserts, Storage API, UDFs, scripting, partitioning, time travel, materialized views, row access policies, dbt, Airflow, Spark, the `bq` CLI, observability, and more.
- [**Reference**](https://jjviscomi.github.io/bqemulator/latest/reference/configuration/) — configuration, CLI, REST coverage, SQL function mapping, compatibility matrix, conformance coverage matrix, out-of-scope catalogue, troubleshooting.
- [**Architecture**](https://jjviscomi.github.io/bqemulator/latest/architecture/overview/) — hexagonal architecture, storage model, SQL translation, jobs lifecycle, Storage Read/Write API design, scripting, UDFs, versioning, row access, specialized types, observability, testing strategy, conformance tier.
- [**ADRs**](https://jjviscomi.github.io/bqemulator/latest/adr/0001-use-duckdb/) — 42 Architecture Decision Records documenting every non-obvious design choice.

## Examples

Every example under [`docs/examples/`](docs/examples/) is a complete, runnable project with its own `make test` validated by CI:

| Toolchain | Example | What it demonstrates |
|---|---|---|
| Python | [`python/pytest-integration`](docs/examples/python/pytest-integration/) | Flask app + auto-discovered `bqemu_client` fixture |
| Python | [`python/dbt-local`](docs/examples/python/dbt-local/) | `dbt build` cycle via endpoint override |
| Python | [`python/airflow-dag-test`](docs/examples/python/airflow-dag-test/) | `BigQueryInsertJobOperator` DAG via offline `dag.test()` |
| Python | [`python/pyspark-bigquery`](docs/examples/python/pyspark-bigquery/) | Storage Read → Arrow → Spark DataFrame |
| Node.js | [`nodejs/nestjs-app`](docs/examples/nodejs/nestjs-app/) | NestJS + Jest + supertest e2e |
| Node.js | [`nodejs/cloud-run-local`](docs/examples/nodejs/cloud-run-local/) | Cloud Run-shaped Express + docker-compose |
| Go | [`go/beam-pipeline`](docs/examples/go/beam-pipeline/) | Apache Beam Go SDK + Testcontainers |
| Go | [`go/dataflow-local`](docs/examples/go/dataflow-local/) | Stand-alone Go ETL binary |
| Java | [`java/spring-boot`](docs/examples/java/spring-boot/) | Spring Boot + Testcontainers |
| Scala | [`java/scio`](docs/examples/java/scio/) | Spotify Scio (Scala-on-Beam) pipeline |
| Compose | [`docker-compose/full-stack`](docs/examples/docker-compose/full-stack/) | App + emulator + Prometheus + Grafana |
| CI | [`ci-recipes/github-actions`](docs/examples/ci-recipes/github-actions/) | Service-container + Testcontainers patterns |
| CI | [`ci-recipes/gitlab-ci`](docs/examples/ci-recipes/gitlab-ci/) | `services:` alias on the CI network |
| CI | [`ci-recipes/circleci`](docs/examples/ci-recipes/circleci/) | Docker-secondary + machine executor |

## Project status

`bqemulator` is at **v1.1.2** — first minor on the production-stable
line. SemVer applies: breaking changes ship only in MAJOR
versions, preceded by ≥1 MINOR with deprecation warnings;
deprecated APIs remain for ≥2 MINOR versions or 6 months.

Maturity signals:

- ✅ 42 Architecture Decision Records covering every non-obvious design choice (`docs/adr/0001`–`0042`).
- ✅ ≥90% line + branch coverage gated by CI (`make verify`).
- ✅ 7 test tiers passing (unit + property + integration + conformance + e2e + perf + chaos).
- ✅ 5-client e2e matrix (Python · Node.js · Go · Java · `bq` CLI).
- ✅ Mutation-tier (`mutmut`) pilot landed on pure-domain modules.
- ✅ Fuzz-tier (`Atheris`) harnesses on the SQL translator, dynamic-protobuf decoder, and Arrow bridge.
- ✅ Differential-tier row-order perturbation of the entire conformance corpus passes.
- ✅ Performance baselines committed for `darwin-arm64`, with regression gates (`pytest-benchmark` `--benchmark-compare-fail=median:10%`).
- ✅ PyPI publish via Trusted Publishing (sigstore-attested wheels) — `pip install bqemulator==1.1.2` resolves from [PyPI](https://pypi.org/project/bqemulator/).
- ✅ GHCR publish with keyless cosign signatures — `docker pull ghcr.io/jjviscomi/bqemulator:1.1.2` resolves and the image is cosign-verifiable.

See [`CHANGELOG.md`](CHANGELOG.md) for the complete release-by-release inventory.

## Contributing

We welcome contributions of all sizes. Start with **[CONTRIBUTING.md](CONTRIBUTING.md)** for the mechanics; **[AGENTS.md](AGENTS.md)** captures the project's day-to-day conventions; and **[`docs/architecture/overview.md`](docs/architecture/overview.md)** is the canonical architectural reference.

Pull requests are squash-merged into `main` with a Conventional Commits subject; commits carry a [DCO](https://developercertificate.org/) sign-off (`git commit -s`). The full review policy lives in [GOVERNANCE.md](GOVERNANCE.md).

## Community

- 💬 **[GitHub Discussions](https://github.com/jjviscomi/bqemulator/discussions)** — design questions, usage questions, and general help.
- 🐛 **[Issues](https://github.com/jjviscomi/bqemulator/issues)** — bug reports and feature requests. Please search existing issues first.
- 🔒 **[Security advisories](https://github.com/jjviscomi/bqemulator/security/advisories/new)** — report vulnerabilities privately via the GitHub Security Advisory flow (see [SECURITY.md](SECURITY.md) for our disclosure policy).
- 📜 **[Code of Conduct](CODE_OF_CONDUCT.md)** — adapted from the Contributor Covenant 2.1.

## License

`bqemulator` is released under the **[Apache License 2.0](LICENSE)**.

## Acknowledgements

- [`goccy/bigquery-emulator`](https://github.com/goccy/bigquery-emulator) for blazing the trail and providing a decade of issue reports that seeded our regression corpus.
- [DuckDB](https://duckdb.org/), [SQLGlot](https://github.com/tobymao/sqlglot), [FastAPI](https://fastapi.tiangolo.com/), [Pydantic](https://docs.pydantic.dev/), [Hatchling](https://hatch.pypa.io/), and the Google Cloud client library teams whose work makes this project tractable.
- The [Apache Beam](https://beam.apache.org/), [dbt](https://www.getdbt.com/), [Airflow](https://airflow.apache.org/), [PySpark](https://spark.apache.org/), [Spotify Scio](https://spotify.github.io/scio/), [NestJS](https://nestjs.com/), and [Spring Boot](https://spring.io/projects/spring-boot) communities whose work the example projects compose with.
