Skip to main content

A helper package for Google BigQuery operations

Project description

BigQuery Helper

BigQuery Helper is a Python package that simplifies working with Google BigQuery. It provides an easy-to-use interface for common BigQuery operations such as executing queries, inserting rows, and working with DataFrames.

Installation

You can install BigQuery Helper using pip:

pip install bigquery-helper

Usage

To use BigQuery Helper, you'll need a Google Cloud project and credentials. Here's how to get started:

  1. Set up a Google Cloud project and enable the BigQuery API.

  2. Create a service account and download the JSON key file.

  3. Set the GOOGLE_APPLICATION_CREDENTIALS environment variable to the path of your JSON key file:

    export GOOGLE_APPLICATION_CREDENTIALS="/path/to/your/keyfile.json"
    

    Alternatively, you can pass the credentials directly when initializing the BigQueryHelper.

Here's a quick example of how to use BigQuery Helper:

from bigquery_helper import BigQueryHelper

# Initialize BigQueryHelper
bq_helper = BigQueryHelper(project_id="your-project-id", credentials="/path/to/your/keyfile.json")

# Execute a query and get results as a DataFrame
query = "SELECT * FROM `your_dataset.your_table` LIMIT 10"
df = bq_helper.query_to_dataframe(query)
print(df)

# Insert rows into a table
rows_to_insert = [
    {"column1": "value1", "column2": 123},
    {"column1": "value2", "column2": 456}
]
bq_helper.insert_rows("your_dataset.your_table", rows_to_insert)

# Upload a DataFrame to BigQuery
import pandas as pd
df_to_upload = pd.DataFrame({"column1": ["a", "b"], "column2": [1, 2]})
bq_helper.dataframe_to_table(df_to_upload, "your_dataset.new_table", if_exists="replace")

# Update a column in a table
bq_helper.update_column("your_dataset.your_table", "id_column", "status_column", [1, 2, 3])

# Get schema of a table
schema = bq_helper.get_schema("your_dataset.your_table")
print(schema)

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bigquery-helper-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

bigquery_helper-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file bigquery-helper-0.1.0.tar.gz.

File metadata

  • Download URL: bigquery-helper-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.11.4

File hashes

Hashes for bigquery-helper-0.1.0.tar.gz
Algorithm Hash digest
SHA256 45826157decb7bfe51bc648c4bf8decf8aa142dba0b842f6b12bbc1b609ccd43
MD5 ab5ffa0a8cbff5d9560853c6673225c0
BLAKE2b-256 ac2bf5394df8d2b4bbb2b892171067ed44e0e34e3232fd3718ef1d132713d0bf

See more details on using hashes here.

File details

Details for the file bigquery_helper-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for bigquery_helper-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8d0257b9686f06701a8b6efa557a54d37892afc56648ce86110075f0ed8d13cc
MD5 a5a19b1652af83861cc536f772fae643
BLAKE2b-256 43c60db922bb8420eb7b3e0a1dc5caba8a7e19aea1d0a439ebd9e33116be7e91

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page