{"id":22981929,"url":"https://github.com/simple-dev-tools/gfluent","last_synced_at":"2025-08-13T17:34:27.955Z","repository":{"id":44568160,"uuid":"355767077","full_name":"simple-dev-tools/gfluent","owner":"simple-dev-tools","description":"A fluent-style Google Cloud Client","archived":false,"fork":false,"pushed_at":"2024-04-29T23:25:03.000Z","size":115,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-13T18:18:26.445Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/simple-dev-tools.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":"2021-04-08T04:50:26.000Z","updated_at":"2024-04-29T23:25:06.000Z","dependencies_parsed_at":"2023-02-08T17:10:15.020Z","dependency_job_id":null,"html_url":"https://github.com/simple-dev-tools/gfluent","commit_stats":null,"previous_names":[],"tags_count":16,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simple-dev-tools%2Fgfluent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simple-dev-tools%2Fgfluent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simple-dev-tools%2Fgfluent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/simple-dev-tools%2Fgfluent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/simple-dev-tools","download_url":"https://codeload.github.com/simple-dev-tools/gfluent/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":229634030,"owners_count":18101938,"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":[],"created_at":"2024-12-15T02:14:21.677Z","updated_at":"2024-12-15T02:14:22.202Z","avatar_url":"https://github.com/simple-dev-tools.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Google Cloud Fluent Client\n\n[![Unit Testing](https://github.com/simple-dev-tools/gfluent/actions/workflows/ut.yml/badge.svg)](https://github.com/simple-dev-tools/gfluent/actions/workflows/ut.yml)\n[![Deployment](https://github.com/simple-dev-tools/gfluent/actions/workflows/deployment.yml/badge.svg)](https://github.com/simple-dev-tools/gfluent/actions/workflows/deployment.yml)\n[![PyPI version](https://badge.fury.io/py/gfluent.svg)](https://badge.fury.io/py/gfluent)\n\n*Version: 1.2.1*\n\nThis is a lightweight wrapper on top of Google Cloud Platform Python SDK client libraries `BigQuery`,\n`Storage` and `Spreadsheet`. It is a great package for Data Engineers for craft data pipeline by using\n`BigQuery` and `Storage` as major services from Google Cloud Platform.\n\nThe purpose of this package are,\n\n- Having a consistent way of using the GCP client libraries\n- Manage the version in a single place if multiple teams are using the GCP client libraries\n- Make it easier to accomplish the typical Data Engineering tasks (copy data, load and export)\n- The code explains what it does\n\n\nThe current embedded client libraires versions are,\n\n- google-api-python-client==2.36.0\n- google-cloud-bigquery==2.32.0\n- google-cloud-storage==2.1.0\n\n## Build Data Pipeline on BigQuery\n\nYou (A Data Engineer) are asked to,\n\n- Upload multiple `json` files from your local drive to GCS\n- Import those files to a BigQuery staging table\n- Run a SQL query based on the staging table by joining existing tables, and store the result\nto a new table\n\n\nTo accomplish the task, here are the source code,\n\n```python\n\nfrom gfluent import BQ, GCS\n\nproject_id = \"here-is-you-project-id\"\nbucket_name = \"my-bucket\"\ndataset = \"sales\"\ntable_name = \"products\"\nprefix = \"import\"\nlocal_path = \"/user/tom/products/\" # there are few *.json files in this directory\n\n# uplaod files to GCS bucket\n(\n    GCS(project_id)\n    .local(path=local_path, suffix=\".json\" )\n    .bucket(bucket_name)\n    .prefix(prefix)\n    .upload()\n)\n\n# create the target dataset (in case not exists)\nBQ(project_id).create_dataset(dataset, location=\"US\")\n\n# load json files to BigQuery table\nuri = f\"gs://{bucket_name}/{prefix}/*.json\"\nnumber_of_rows = (\n    BQ(project_id)\n    .table(f\"{dataset}.{table_name}\")\n    .mode(\"WRITE_APPEND\")               # don't have to, default mode\n    .create_mode(\"CREATE_IF_NEEDED\")    # don't have to, default mode\n    .format(\"NEWLINE_DELIMITED_JSON\")   # don't have to, default format\n    .gcs(uri).load(location=\"US\")\n)\n\nprint(f\"{number_of_rows} rows are loaded\")\n\n\n# run a SQL query and save to a final table\nfinal_table = \"sales_summary\"\nsql = \"\"\"\n    select t1.col1, t2.col2, t2.col3\n    FROM\n        sales.products t1\n    JOIN\n        other.category t2\n    ON  t1.prod_id = t2.prod_id\n\"\"\"\n\nnumber_of_rows = (\n    BQ(product_id)\n    .table(f\"{dataset}.{final_table}\")\n    .sql(sql)\n    .create_mode(\"CREATE_NEVER\")    # have to, don't want to create new table\n    .query()\n)\n\nprint(f\"{number_of_rows} rows are loaded to {final_table}\")\n\n\n# now let's query the new table\nrows = (\n    BQ(product_id)\n    .sql(f\"select col1, col2 from {dataset}.{final_table} limit 10\")\n    .query()\n)\n\nfor row in rows:\n    print(row.col1, row.col2)\n```\n\n## Loading data from Spreadsheet to BigQuery\n\nHere is another example to use the `Sheet` class for loading data from Google Spreadsheet.\n\n```python\nimport os\nfrom gfluent import Sheet, BQ\n\nproject_id = 'your-project-id'\nsheet_id = 'the-google-spreadsheet-id'\n\n# assume the data is on the sheet `data` and range is `A1:B4`\nsheet = Sheet(\n    os.getenv(\"GOOGLE_APPLICATION_CREDENTIALS\")\n).sheet_id(sheet_id).worksheet(\"data!A1:B4\")\n\nbq = BQ(project=project_id).table(\"target_dataset.table\")\n\nsheet.bq(bq).load(location=\"EU\")\n```\n\n## Documents\n\nHere is the [document](https://gfluent.readthedocs.io/en/latest/#), and please refer to the test\ncases to see more real examples.\n\n\n## Installation\n\nInstall from PyPi,\n\n```bash\npip install -U gfluent\n```\n\nOr build and install from source code,\n\n```bash\ngit clone git@github.com:simple-dev-tools/gfluent.git\ncd gfluent\nmake test-ut\npython setup.py install\n```\n\n\n## Contribution\n\nAny kinds of contribution is welcome, including report bugs, add feature or enhance the document. Please\nbe noted,\n\n- Unit Testing with mock is intensively used, because we don't want to connect to a real GCP project\n- Please install `pre-commit` by using `pip install pre-commit` then `pre-commit install`\n- `bump2version` is used for update the version tag in various files\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimple-dev-tools%2Fgfluent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsimple-dev-tools%2Fgfluent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsimple-dev-tools%2Fgfluent/lists"}