Skip to main content

Help modules for different applications, especially for google cloud

Project description

SIBR Module

PyPI version A collection of helper modules for interacting with Google Cloud Platform services, designed to simplify common workflows. This package provides easy-to-use classes for BigQuery, Google Cloud Storage, Secret Manager, and Cloud Logging.

Features

  • BigQuery: Easily upload DataFrames to BigQuery tables with automatic schema detection and support for append, replace, and merge operations.
  • CStorage: Upload and download files to and from Google Cloud Storage buckets.
  • SecretsManager: Securely access secrets from Google Secret Manager.
  • Logger: A flexible logger that supports both local file logging and integration with Google Cloud Logging.

Installation

You can install the package from PyPI:

pip install sibr-module

Quickstart

Ensure you are authenticated with Google Cloud. You can do this by running:

gcloud auth application-default login

import pandas as pd
from sibr_module import BigQuery, Logger

# --- 1. Set up a logger ---
# This will log to a local file and, if enabled, to Google Cloud Logging
logger = Logger(log_name="my_app_logger", enable_cloud_logging=True)
logger.info("Application starting up.")

# --- 2. Prepare your data ---
data = {'name': ['Alice', 'Bob'], 'score': [85, 92]}
my_dataframe = pd.DataFrame(data)

# --- 3. Use the BigQuery helper ---
try:
    # Initialize the client with your Google Cloud Project ID
    bq_client = BigQuery(project_id="your-gcp-project-id", logger=logger)

    # Upload the DataFrame to a BigQuery table
    bq_client.to_bq(
        df=my_dataframe,
        dataset_name="my_dataset",
        table_name="my_table",
        if_exists="append"  # Options: 'append', 'replace', or 'merge'
    )

    logger.info("Successfully uploaded data to BigQuery.")

except Exception as e:
    logger.error(f"An error occurred: {e}")

Usage Details

BigQuery

The BigQuery class handles interactions with Google BigQuery.

  • to_bq(df, dataset_name, table_name, if_exists='append', merge_on=None): Uploads a pandas DataFrame.
    • if_exists='append': Adds data to an existing table.
    • if_exists='replace': Deletes the existing table and creates a new one.
    • if_exists='merge': Updates existing rows and inserts new ones. Requires merge_on to be set with a list of key columns.
    • read_bq(query): Executes a query and returns the result as a pandas DataFrame.

CStorage

The CStorage class simplifies file operations with Google Cloud Storage.

  • upload(local_file_path, destination_blob_name): Uploads a local file to the bucket.

  • download(source_blob_name, destination_file_path): Downloads a file from the bucket.

SecretsManager

Access your secrets easily.

  • get_secret(secret_id): Retrieves the latest version of a secret by its ID.

Contributing

Contributions are welcome! Please open an issue or submit a pull request if you have any improvements or bug fixes.

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

sibr_module-0.1.5.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sibr_module-0.1.5-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

Details for the file sibr_module-0.1.5.tar.gz.

File metadata

  • Download URL: sibr_module-0.1.5.tar.gz
  • Upload date:
  • Size: 12.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for sibr_module-0.1.5.tar.gz
Algorithm Hash digest
SHA256 1a766e8a39acbda2c2ea7578a22e5f86ef5aed404e268d7b5ee7cb4b4e5b7ce8
MD5 f2738f828f3acff0d849a9d961956a6f
BLAKE2b-256 42f985ce930082a04d96937c1220e79855103fb925bae77592c9d8c1cb5826f3

See more details on using hashes here.

File details

Details for the file sibr_module-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: sibr_module-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 11.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.6

File hashes

Hashes for sibr_module-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 7dbd0abb3cc3d8d277949cd38b7ffb218619d8238e5a1151d621d97d2bbae648
MD5 509db351067e09948a2ab0d1b5ab540c
BLAKE2b-256 7b858a0dcf6c9beb481275970b589557c1fa42c2d76ad647a423082487202003

See more details on using hashes here.

Supported by

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