Python BigQuery API - get table schema
An alternative is, after you have your client and table instances, to do something like this:
import io
f = io.StringIO("")
client.schema_to_json(table.schema, f)
print(f.getvalue())
You can always get the table.schema
variable and iterate over it, since the table is a list made of SchemaField values:
result = ["{0} {1}".format(schema.name,schema.field_type) for schema in table.schema]
Result for that same dataset and table:
['word STRING', 'word_count INTEGER', 'corpus STRING', 'corpus_date INTEGER']
here, schema
has been expired.