I'm trying to create using BQ API a table from an external source (google sheet).
project_id = 'XXX'
dataset_name= f'{project_id}.brodmann_dev'
table_name = f'{dataset_name}.test2'
from google.cloud import bigquery
from google.cloud.bigquery.table import Table
from google.cloud.bigquery.schema import SchemaField
from google.cloud.bigquery.external_config import GoogleSheetsOptions
source_uri="https://docs.google.com/spreadsheets/d/XXXX"
external_config = bigquery.ExternalConfig(source_format=bigquery.ExternalSourceFormat.GOOGLE_SHEETS)
external_config.source_uri=source_uri
schema = [SchemaField('id', 'STRING', 'NULLABLE', None, (), None)]
table = bigquery.Table(table_name,schema=schema)
table.external_config=external_config
client.delete_table(table, not_found_ok=True)
client.create_table(table)
The table is created but without any reference to the source uri