{"id":26938829,"url":"https://github.com/42DIGITAL/bqtools","last_synced_at":"2025-04-02T14:14:31.947Z","repository":{"id":56096664,"uuid":"176760535","full_name":"42DIGITAL/bqtools","owner":"42DIGITAL","description":"Python Tools for BigQuery","archived":false,"fork":false,"pushed_at":"2023-02-21T15:22:19.000Z","size":54,"stargazers_count":3,"open_issues_count":2,"forks_count":3,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-02T14:14:27.027Z","etag":null,"topics":["bigquery","bigquery-schema","migrations","python"],"latest_commit_sha":null,"homepage":"https://www.42digital.de","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/42DIGITAL.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-03-20T15:14:01.000Z","updated_at":"2023-06-17T14:33:29.000Z","dependencies_parsed_at":"2025-02-15T12:41:45.177Z","dependency_job_id":null,"html_url":"https://github.com/42DIGITAL/bqtools","commit_stats":null,"previous_names":["42digital/bqorm"],"tags_count":8,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/42DIGITAL%2Fbqtools","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/42DIGITAL%2Fbqtools/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/42DIGITAL%2Fbqtools/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/42DIGITAL%2Fbqtools/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/42DIGITAL","download_url":"https://codeload.github.com/42DIGITAL/bqtools/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246828507,"owners_count":20840474,"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","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","bigquery-schema","migrations","python"],"created_at":"2025-04-02T14:14:30.988Z","updated_at":"2025-04-02T14:14:31.941Z","avatar_url":"https://github.com/42DIGITAL.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/42DIGITAL/bqtools.svg?branch=master)](https://travis-ci.org/42DIGITAL/bqtools) [![PyPI version](https://badge.fury.io/py/bqtools.svg)](https://badge.fury.io/py/bqtools)\n\n# Python Tools for BigQuery\n\n### Why?\nFor data collection and data exploration, we like to work with [BigQuery](https://cloud.google.com/bigquery/). But we have not found a python library, to easily handle recurring tasks like adding new data (of potentially inconsistent schema) and schema migrations. So we took a couple of our solutions for those tasks and put them into this library.\n\n### What?\n`bqtools` provides a light-weight solution to explicit schema management with python-native types (unlike pandas dtype) and \nsome convenient type checking, inference and conversions. Table-objects created by `bqtools` can be read from BigQuery, stored locally, read from a local file and written to BigQuery. Table schemas can be changed and data can be added or modified.\n\n### Install\n```bash\npip install --upgrade bqtools\n```\n\n## Examples:\n### Create basic tables\n```python\nfrom fourtytwo import bqtools\n\nschema = [\n    {'name': 'number', 'field_type': 'INTEGER'},\n    {'name': 'text', 'field_type': 'STRING'},\n    {'name': 'struct', 'field_type':'RECORD', 'mode':'REPEATED', \n        'fields': [\n            {'name':'integer', 'field_type':'INTEGER'},\n            {'name':'text', 'field_type':'STRING'}\n        ]\n    }\n]\n# valid BigQuery types see: \n# https://cloud.google.com/bigquery/docs/reference/standard-sql/data-types\n# geo and array are currently not/not fully supported\n\n# data = columns of lists\ntable = bqtools.BQTable(\n    schema=schema, \n    data=[[1, 2, 3, 4], ['a', 'b', 'c', 'd']]\n)\n\n# data = rows of dicts\ntable = bqtools.BQTable(\n    schema=schema, \n    data=[\n        {'number': 1, 'text': 'a'}, \n        {'number': 2, 'text': 'b'},\n        ...\n    ]\n)\n```\n\n### View data\n```python\nprint(table.data)       # list of all columns\nprint(table.rows(n=10)) # list of first n rows\n\n# convert to pandas.DataFrame\ndf = table.to_df()               \n# warning: pandas dtypes may be inconsistent \n# with BigQuery Schema field_types\n```\n\n### Append data\n```python\nrows = [{'number': 5, 'text': 'e'}]\ntable.append(rows)\n\nrow = [[6, 'f']]\ntable.append(rows)\n```\n\n### Load table from BigQuery\n```python\n# requires environment variable GOOGLE_APPLICATION_CREDENTIALS \n# or parameter credentials='path-to-credentials.json'\ntable = bqtools.read_bq(\n    table_ref='project_id.dataset_id.new_table_id', \n    limit=10,           # limit query rows\n    schema_only=False   # set True to only add data\n)\n```\n\n### Modify table schema\n```python\n# change column order and field_type\nnew_schema = [\n    {'name': 'text', 'field_type': 'STRING'},\n    {'name': 'number', 'field_type': 'FLOAT'},\n]\ntable.schema(new_schema)\n\n# change column names\ntable.rename(columns={'number': 'decimal'})\n```\n\n### Write table to BigQuery\n```python\n# requires environment variable GOOGLE_APPLICATION_CREDENTIALS\n# or parameter credentials='path-to-credentials.json'\ntable.to_bq(table_ref, mode='append')\n```\n\n### Persist tables locally\n```python\n# write to local file (compressed binary format)\ntable.save('local_table.bqt')\n\n# load from local file\ntable = bqtools.load('local_table.bqt')\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F42DIGITAL%2Fbqtools","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F42DIGITAL%2Fbqtools","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F42DIGITAL%2Fbqtools/lists"}