Skip to content

duizendstra/bigquery-schemas

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

53 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Google API BigQuery Schemas

This repository contains a collection of BigQuery table schemas for various Google APIs. These schemas can be used to create tables in Google's BigQuery data warehousing service for storing responses obtained from different Google APIs.

Structure

The repository is structured as follows:

├── admin_directory  
│ ├── users.json 
│ ├── ... 
├── drive  
│ ├── files.json  
│ ├── ...
├── ...

Each subdirectory represents a different Google API (like 'admin_directory' for the Admin SDK Directory API, 'analytics' for the Google Analytics API, and so on). Within each subdirectory, there are JSON files representing different endpoints of the respective API (like 'users.json', 'groups.json', etc. for the Admin SDK Directory API).

Usage

To use these schemas, follow these steps:

  1. Clone this repository.
  2. Use the JSON schema files to create tables in BigQuery.

Here's a Python snippet using the google-cloud-bigquery client library:

from google.cloud import bigquery
import json
import requests

PROJECT_ID = "your_project_id"
DATASET_ID = "your_dataset_id"
TABLE_ID = "your_table_id"
SCHEMA_URL = "https://raw.githubusercontent.com/duizendstra/bigquery-schemas/main/photos/album.json"

# Initialize a BigQuery client
client = bigquery.Client(project=PROJECT_ID)

# Define your dataset
dataset_ref = client.dataset(DATASET_ID)


# Fetch the raw content of the schema file
response = requests.get(SCHEMA_URL)
schema_json = response.json()

# Convert the JSON schema to BigQuery SchemaField objects
schema = [bigquery.SchemaField.from_api_repr(field) for field in schema_json]

# Create a new table
table_ref = dataset_ref.table(TABLE_ID)
table = bigquery.Table(table_ref, schema=schema)
table = client.create_table(table)

print(f"Created table {table.project}.{table.dataset_id}.{table.table_id}")

Replace 'your_project_id', 'your_dataset_id', 'schema_file_url', and 'your_table_id' with your dataset ID, the url to the schema file, and your table ID, respectively.

Contributing

Contributions are welcome! Please feel free to submit a pull request with any corrections to existing schemas or addition of new ones.

Disclaimer

This repository is not affiliated with, officially maintained by, or in any way officially connected with Google Inc. or any of its subsidiaries or its affiliates.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published