Install & Compatibility
Where this runs
tested against v7.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 54.6MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 4.0s · import 0.000s · 55MB
54MB installed
● package 54MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
BigqueryClient
✓ from gcloud.rest.bigquery import BigqueryClient
✗ from gcloud.rest.bigquery import BigqueryClient
This quickstart demonstrates how to initialize the BigqueryClient using default Google Cloud credentials (e.g., `gcloud auth application-default login` or `GOOGLE_APPLICATION_CREDENTIALS`), run a simple SQL query, and fetch its results asynchronously. Ensure the `GCLOUD_PROJECT` environment variable is set to your Google Cloud project ID.
import asyncio
import os
from gcloud_aio_auth import build_default_credentials
from gcloud_aio_bigquery import BigqueryClient
async def main():
project_id = os.environ.get("GCLOUD_PROJECT", "")
if not project_id:
print("Please set the GCLOUD_PROJECT environment variable.")
return
# Using default credentials (e.g., from gcloud CLI, service account JSON in GOOGLE_APPLICATION_CREDENTIALS)
async with build_default_credentials(
scopes=["https://www.googleapis.com/auth/cloud-platform"]
) as credentials:
async with BigqueryClient(
project=project_id, credentials=credentials
) as client:
# Execute a simple query
print(f"Running query in project: {project_id}")
query_job = await client.query(
project_id=project_id,
query="SELECT 1 AS one, 'hello' AS greeting",
use_legacy_sql=False,
location="US" # Or your preferred dataset location
)
# Wait for the job to complete and fetch results
results = await client.get_job_results(
project_id=project_id,
job_id=query_job["jobReference"]["jobId"],
location=query_job["jobReference"]["location"]
)
print("Query results:")
if results and "rows" in results:
for row in results["rows"]:
# Each 'f' element corresponds to a column, 'v' is the value
print([col["v"] for col in row["f"]])
else:
print("No rows returned or unexpected result format.")
if __name__ == "__main__":
asyncio.run(main())
Debug
Known issues
breaking`gcloud-aio-auth` (a core dependency) dropped support for Python 3.9 in version 5.4.4. While `gcloud-rest-bigquery` technically supports Python 3.9, installing `gcloud-aio-auth>=5.4.4` will cause issues.fixUpgrade your Python environment to 3.10 or newer, or pin your `gcloud-aio-auth` dependency to `<5.4.4` in your `requirements.txt`.
affects: gcloud-aio-auth>=5.4.4 (which affects gcloud-rest-bigquery if installed on Python 3.9)
gotchaIncorrect `asyncio` event loop management (e.g., calling `asyncio.run()` multiple times in the same thread, or not awaiting coroutines) can lead to `RuntimeError: Event loop is closed` or deadlocks.fixEnsure `asyncio.run()` is called only once per thread. Use `async with` for client and credential objects to ensure proper resource cleanup. Always `await` coroutines and `async` functions.
affects: All versions
gotchaDefault authentication credentials might not include all necessary OAuth 2.0 scopes for every BigQuery API call, leading to `403 Permission denied` errors.fixConsult the BigQuery API documentation for the required scopes for your specific operations (e.g., `https://www.googleapis.com/auth/bigquery`, `https://www.googleapis.com/auth/devstorage.read_only`). Pass these explicitly to `build_default_credentials` or `build_from_service_account_info`.
affects: All versions
Upgrade
Version history
7.1.0latest on PyPI · released Feb 16, 2024
Audit
Dependencies
gcloud-aio-authrequiredCore dependency for Google Cloud authentication.
gcloud-aio-corerequiredCore dependency for common gcloud-aio functionality.