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 hashes)

Uploaded Source

Built Distribution

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

Uploaded Python 3

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