{"id":19685415,"url":"https://github.com/kislerdm/gbqschema_converter","last_synced_at":"2025-07-21T23:34:11.937Z","repository":{"id":57433185,"uuid":"253862654","full_name":"kislerdm/gbqschema_converter","owner":"kislerdm","description":"Python library to convert google bigquery table schema to jsonschema","archived":false,"fork":false,"pushed_at":"2021-10-12T00:44:35.000Z","size":44,"stargazers_count":3,"open_issues_count":3,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-19T08:05:17.743Z","etag":null,"topics":["bigquery-schema","google-bigquery","google-cloud-platform","jsonschema","python3"],"latest_commit_sha":null,"homepage":"https://pypi.org/project/gbqschema-converter","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kislerdm.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-07T17:16:38.000Z","updated_at":"2023-06-21T12:53:55.000Z","dependencies_parsed_at":"2022-08-27T23:53:16.363Z","dependency_job_id":null,"html_url":"https://github.com/kislerdm/gbqschema_converter","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/kislerdm/gbqschema_converter","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kislerdm%2Fgbqschema_converter","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kislerdm%2Fgbqschema_converter/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kislerdm%2Fgbqschema_converter/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kislerdm%2Fgbqschema_converter/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kislerdm","download_url":"https://codeload.github.com/kislerdm/gbqschema_converter/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kislerdm%2Fgbqschema_converter/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266403142,"owners_count":23923404,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bigquery-schema","google-bigquery","google-cloud-platform","jsonschema","python3"],"created_at":"2024-11-11T18:21:48.539Z","updated_at":"2025-07-21T23:34:11.911Z","avatar_url":"https://github.com/kislerdm.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google BigQuery Table Schema Converter\n\n[![license](https://img.shields.io/pypi/l/ansicolortags.svg)](./LICENSE)\n[![pyversion](https://img.shields.io/static/v1?label=python\u0026color=blue\u0026message=3.6%20|%203.7%20|%203.8)](./)\n[![coverage](https://img.shields.io/static/v1?label=coverage\u0026color=brightgreen\u0026message=94%25)](./)\n[![test](https://img.shields.io/static/v1?label=tests\u0026color=success\u0026message=100%25)](./)\n[![downloads](https://pepy.tech/badge/gbqschema-converter)](https://pepy.tech/project/gbqschema-converter)\n\nPython library to convert [Google BigQuery table schema](https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types#datetime_type) into [draft-07](https://json-schema.org/draft-07/json-schema-release-notes.html) [json schema](https://json-schema.org/) and vice versa.\n\nThe library includes two main modules:\n\n```bash\ngbqschema_converter\n├── gbqschema_to_jsonschema.py\n└── jsonschema_to_gbqschema.py\n```\n\nEach of those modules has two main functions:\n\n- `json_representation`: corresponds to json output (input for `gbqschema_to_jsonschema`).\n- `sdk_representation`: corresponds to [Google Python SDK format](https://googleapis.dev/python/bigquery/latest/generated/google.cloud.bigquery.schema.SchemaField.html) output (input for `gbqschema_to_jsonschema`).\n\n## Installation\n\n```bash\npython3 -m venv env \u0026\u0026 source ${PWD}/env/bin/activate\n(env) pip install --no-cache-dir gbqschema_converter\n```\n\n## Usage: CLI\n\n### Convert json-schema to GBQ table schema\n\n```bash\n(env) json2gbq -h\nusage: json2gbq [-h] (-i INPUT | -f FILE)\n\nGoogle BigQuery Table Schema Converter\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i INPUT, --input INPUT\n                        Input object as string.\n  -f FILE, --file FILE  Input object as file path.\n```\n\n#### Example: stdin\n\nExecution:\n\n```bash\n(env) json2gbq -i '{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"$ref\": \"#/definitions/element\"\n  },\n  \"definitions\": {\n    \"element\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"att_01\": {\n          \"type\": \"integer\",\n          \"description\": \"Att 1\"\n        },\n        \"att_02\": {\n          \"type\": \"number\",\n          \"description\": \"Att 2\"\n        },\n        \"att_03\": {\n          \"type\": \"string\"\n        },\n        \"att_04\": {\n          \"type\": \"boolean\"\n        },\n        \"att_05\": {\n          \"type\": \"string\",\n          \"format\": \"date\"\n        },\n        \"att_06\": {\n          \"type\": \"string\",\n          \"format\": \"date-time\"\n        },\n        \"att_07\": {\n          \"type\": \"string\",\n          \"format\": \"time\"\n        }\n      },\n      \"required\": [\n        \"att_02\"\n      ]\n    }\n  }\n}'\n```\n\nOutput:\n\n```bash\n2020-04-08 21:42:51.700 [INFO ] [Google BigQuery Table Schema Converter] Output (5.52 ms elapsed):\n[\n  {\n    \"description\": \"Att 1\",\n    \"name\": \"att_01\",\n    \"type\": \"INTEGER\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"description\": \"Att 2\",\n    \"name\": \"att_02\",\n    \"type\": \"NUMERIC\",\n    \"mode\": \"REQUIRED\"\n  },\n  {\n    \"name\": \"att_03\",\n    \"type\": \"STRING\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_04\",\n    \"type\": \"BOOLEAN\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_05\",\n    \"type\": \"DATE\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_06\",\n    \"type\": \"TIMESTAMP\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_07\",\n    \"type\": \"STRING\",\n    \"mode\": \"NULLABLE\"\n  }\n]\n```\n\n#### Example: file\n\nExecution:\n\n```bash\n(env) json2gbq -f ${PWD}/data/jsonschema.json\n```\n\nOutput:\n\n```bash\n2020-04-08 21:57:25.516 [INFO ] [Google BigQuery Table Schema Converter] Output (6.39 ms elapsed):\n[\n  {\n    \"description\": \"Att 1\",\n    \"name\": \"att_01\",\n    \"type\": \"INTEGER\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"description\": \"Att 2\",\n    \"name\": \"att_02\",\n    \"type\": \"NUMERIC\",\n    \"mode\": \"REQUIRED\"\n  },\n  {\n    \"name\": \"att_03\",\n    \"type\": \"STRING\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_04\",\n    \"type\": \"BOOLEAN\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_05\",\n    \"type\": \"DATE\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_06\",\n    \"type\": \"TIMESTAMP\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_07\",\n    \"type\": \"STRING\",\n    \"mode\": \"NULLABLE\"\n  }\n]\n```\n\n### Convert GBQ table schema to json-schema\n\n```bash\n(env) gbq2json -h\nusage: gbq2json [-h] (-i INPUT | -f FILE)\n\nGoogle BigQuery Table Schema Converter\n\noptional arguments:\n  -h, --help            show this help message and exit\n  -i INPUT, --input INPUT\n                        Input object as string.\n  -f FILE, --file FILE  Input object as file path.\n```\n\n#### Example: stdin\n\nExecution:\n\n```bash\n(env) gbq2json -i '[\n  {\n    \"description\": \"Att 1\",\n    \"name\": \"att_01\",\n    \"type\": \"INTEGER\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"description\": \"Att 2\",\n    \"name\": \"att_02\",\n    \"type\": \"NUMERIC\",\n    \"mode\": \"REQUIRED\"\n  },\n  {\n    \"name\": \"att_03\",\n    \"type\": \"STRING\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_04\",\n    \"type\": \"BOOLEAN\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_05\",\n    \"type\": \"DATE\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_06\",\n    \"type\": \"DATETIME\",\n    \"mode\": \"NULLABLE\"\n  },\n  {\n    \"name\": \"att_07\",\n    \"type\": \"TIMESTAMP\",\n    \"mode\": \"NULLABLE\"\n  }\n]'\n```\n\nOutput:\n\n```bash\n2020-04-08 21:51:05.370 [INFO ] [Google BigQuery Table Schema Converter] Output (1.08 ms elapsed):\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"$ref\": \"#/definitions/element\"\n  },\n  \"definitions\": {\n    \"element\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"att_01\": {\n          \"type\": \"integer\",\n          \"description\": \"Att 1\"\n        },\n        \"att_02\": {\n          \"type\": \"number\",\n          \"description\": \"Att 2\"\n        },\n        \"att_03\": {\n          \"type\": \"string\"\n        },\n        \"att_04\": {\n          \"type\": \"boolean\"\n        },\n        \"att_05\": {\n          \"type\": \"string\",\n          \"format\": \"date\"\n        },\n        \"att_06\": {\n          \"type\": \"string\",\n          \"pattern\": \"^[0-9]{4}-((|0)[1-9]|1[0-2])-((|[0-2])[1-9]|3[0-1])(|T)((|[0-1])[0-9]|2[0-3]):((|[0-5])[0-9]):((|[0-5])[0-9])(|.[0-9]{1,6})$\"\n        },\n        \"att_07\": {\n          \"type\": \"string\",\n          \"format\": \"date-time\"\n        }\n      },\n      \"additionalProperties\": false,\n      \"required\": [\n        \"att_02\"\n      ]\n    }\n  }\n}\n```\n\n#### Example: file\n\nExecution:\n\n```bash\n(env) gbq2json -f ${PWD}/data/gbqschema.json\n```\n\nOutput:\n\n```bash\n2020-04-08 21:55:20.275 [INFO ] [Google BigQuery Table Schema Converter] Output (1.72 ms elapsed):\n{\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"$ref\": \"#/definitions/element\"\n  },\n  \"definitions\": {\n    \"element\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"att_01\": {\n          \"type\": \"integer\",\n          \"description\": \"Att 1\"\n        },\n        \"att_02\": {\n          \"type\": \"number\",\n          \"description\": \"Att 2\"\n        },\n        \"att_03\": {\n          \"type\": \"string\"\n        },\n        \"att_04\": {\n          \"type\": \"boolean\"\n        },\n        \"att_05\": {\n          \"type\": \"string\",\n          \"format\": \"date\"\n        },\n        \"att_06\": {\n          \"type\": \"string\",\n          \"pattern\": \"^[0-9]{4}-((|0)[1-9]|1[0-2])-((|[0-2])[1-9]|3[0-1])(|T)((|[0-1])[0-9]|2[0-3]):((|[0-5])[0-9]):((|[0-5])[0-9])(|.[0-9]{1,6})$\"\n        },\n        \"att_07\": {\n          \"type\": \"string\",\n          \"format\": \"date-time\"\n        }\n      },\n      \"additionalProperties\": false,\n      \"required\": [\n        \"att_02\"\n      ]\n    }\n  }\n}\n```\n\n## Usage: python program\n\n### Convert json-schema to GBQ table schema\n\n#### Example: output as json\n\n```python\nfrom gbqschema_converter.jsonschema_to_gbqschema import json_representation as converter\n\nschema_in = {\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"$ref\": \"#/definitions/element\",\n  },\n  \"definitions\": {\n    \"element\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"att_01\": {\n          \"type\": \"integer\",\n          \"description\": \"Att 1\"\n        },\n        \"att_02\": {\n          \"type\": \"number\",\n        },\n      }\n      \"required\": [\n        \"att_02\",\n      ],\n    },\n  },\n}\n\nschema_out = converter(schema_in)\nprint(schema_out)\n```\n\nOutput:\n\n```bash\n[{'description': 'Att 1', 'name': 'att_01', 'type': 'INTEGER', 'mode': 'NULLABLE'}, {'name': 'att_02', 'type': 'NUMERIC', 'mode': 'REQUIRED'}]\n```\n\n#### Example: output as list of SchemaField (SDK format)\n\n```python\nfrom gbqschema_converter.jsonschema_to_gbqschema import sdk_representation as converter\n\nschema_in = {\n  \"$schema\": \"http://json-schema.org/draft-07/schema#\",\n  \"type\": \"array\",\n  \"items\": {\n    \"$ref\": \"#/definitions/element\",\n  },\n  \"definitions\": {\n    \"element\": {\n      \"type\": \"object\",\n      \"properties\": {\n        \"att_01\": {\n          \"type\": \"integer\",\n          \"description\": \"Att 1\"\n        },\n        \"att_02\": {\n          \"type\": \"number\",\n        },\n      },\n      \"required\": [\n        \"att_02\",\n      ],\n    },\n  },\n}\n\nschema_out = converter(schema_in)\nprint(schema_out)\n```\n\nOutput:\n\n```bash\n[SchemaField('att_01', 'INTEGER', 'NULLABLE', 'Att 1', ()), SchemaField('att_02', 'NUMERIC', 'REQUIRED', None, ())]\n```\n\n### Convert GBQ table schema to json-schema\n\n#### Example: output as json\n\n```python\nfrom gbqschema_converter.gbqschema_to_jsonschema import json_representation as converter\n\nschema_in = [\n    {\n        'description': 'Att 1',\n        'name': 'att_01',\n        'type': 'INTEGER',\n        'mode': 'NULLABLE'\n    },\n    {\n        'name': 'att_02',\n        'type': 'NUMERIC',\n        'mode': 'REQUIRED'\n    }\n]\n\nschema_out = converter(schema_in)\nprint(schema_out)\n```\n\nOutput:\n\n```bash\n{'$schema': 'http://json-schema.org/draft-07/schema#', 'type': 'array', 'items': {'$ref': '#/definitions/element'}, 'definitions': {'element': {'type': 'object', 'properties': {'att_01': {\n'type': 'integer', 'description': 'Att 1'}, 'att_02': {'type': 'number'}}, 'additionalProperties': False, 'required': ['att_02']}}}\n```\n\n#### Example: output as list of SchemaField (SDK format)\n\n```python\nfrom gbqschema_converter.gbqschema_to_jsonschema import sdk_representation as converter\nfrom google.cloud.bigquery import SchemaField\n\nschema_in = [\n    SchemaField('att_01', 'INTEGER', 'NULLABLE', 'Att 1', ()),\n    SchemaField('att_02', 'NUMERIC', 'REQUIRED', None, ()),\n]\n\nschema_out = converter(schema_in)\nprint(schema_out)\n```\n\nOutput:\n\n```bash\n{'$schema': 'http://json-schema.org/draft-07/schema#', 'type': 'array', 'items': {'$ref': '#/definitions/element'}, 'definitions': {'element': {'type': 'object', 'properties': {'att_01': {\n'type': 'integer', 'description': 'Att 1'}, 'att_02': {'type': 'number'}}, 'additionalProperties': False, 'required': ['att_02']}}}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkislerdm%2Fgbqschema_converter","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkislerdm%2Fgbqschema_converter","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkislerdm%2Fgbqschema_converter/lists"}