Extract data from BigQuery tables, queries, and schemas into Semantica with Application Default Credentials or service-account key-file authentication.

Installation

Basic Usage

Use environment variables (or a .env file with python-dotenv) to keep configuration out of source code. BigQueryIngestor() with no arguments reads from BIGQUERY_* environment variables automatically, once BIGQUERY_PROJECT is set.

Authentication

Environment Variables

All constructor parameters have environment-variable fallbacks:

Table Ingestion

Ingest a table with filters

where and order_by accept raw SQL fragments. They are validated against a blocklist (statement separators, UNION, DML/DDL keywords, comment sequences) but are intended for trusted, operator-controlled input. Do not pass raw end-user text directly to these parameters.

Override project and dataset per call

Ingest from a fully-qualified table

Custom SQL Queries

The query string is passed verbatim to BigQuery. The caller is responsible for correctness and safety of the SQL.

Parameterised queries

Schema Inspection

List tables in a dataset

Export as Semantica Documents

Convert ingested rows to the Semantica document format for use with GraphBuilder:
Feed the documents directly into GraphBuilder:
When text_fields is omitted, all str-typed column values in each row are joined to form the document text. Integer, float, Decimal, and None values are excluded from the default text composition.

Context Manager

Prefer the context manager for batches of queries — it opens one client on entry and closes it on exit, so every call inside the with block reuses the same authenticated session:
Outside a context manager each method call opens and closes a transient client independently.

Connection Testing

Troubleshooting

ImportError: BigQuery ingestion requires optional dependency 'google-cloud-bigquery' Install the optional extra:
google.auth.exceptions.DefaultCredentialsError No credentials were found in the environment. Either:
  • Run gcloud auth application-default login for local development, or
  • Set GOOGLE_APPLICATION_CREDENTIALS to the path of a service-account JSON key file, or
  • Set BIGQUERY_CREDENTIALS_FILE to the path of a service-account JSON key file.
google.api_core.exceptions.Forbidden The service account or user account does not have permission to access the dataset or table. Ensure the account has at minimum:
  • roles/bigquery.dataViewer on the dataset or project
  • roles/bigquery.jobUser on the project
ValidationError: Invalid BigQuery project ID Project IDs may contain letters, digits, hyphens, and underscores, and must start with a letter. Numeric-only or leading-hyphen project IDs are rejected. ValidationError: Invalid table_name Table and dataset names must start with a letter or underscore and contain only letters, digits, and underscores. Hyphens are not permitted in table or dataset names (use underscores instead). Slow queries Use limit and where to restrict the rows fetched. For large analytical queries, consider using ingest_query() with a pre-aggregated SQL statement rather than ingesting raw table rows.

See Also