Skip to main content

A unified cloud db package for AWS, Azure, and GCP

Project description

Cloud DB Connector

This package provides a flexible and secure way to establish connections to various database types, including AWS RDS, Azure SQL, Google Cloud MySQL, and local databases. It includes factory functions and connection classes, as well as helper functions to execute queries and handle database interactions with retry logic.

Package Structure

- db_manager.py        # Factory function to create DB connection based on the service type
- db_connection.py     # Interface to get DB connection
- aws_db.py            # AWS RDS MySQL connection class
- azure_db.py          # Azure SQL Database connection class
- gcp_db.py            # Google Cloud MySQL connection class
- local_db.py          # Local MySQL database connection class
- rds_execute.py       # Utility to execute SQL queries on the databases

Installation

Ensure all necessary dependencies are installed:

pip install clouddatabridge

Additional Requirements for Azure SQL Database

To connect to an Azure SQL Database, an ODBC driver is required. Install the appropriate driver for your operating system:

Follow the official installation instructions on the linked pages for your OS.

Usage

Setting Up a Database Connection

The db_manager.py file contains a factory function, create_db_connection, to create a connection based on the chosen service (local, aws, azure, gcp). You can also use the get_db_connection function in db_connection.py for easier configuration management.

from clouddatabridge.rds_execute import rds_execute

query = "SELECT * FROM person"

local_result = rds_execute(
    service="gcp",
    query=query,
    host="your-azure-sql-hostname",
    user="your-username",
    password="your-password",
    database="your-database",
    port=3306
    )

print(local_result)

Components Overview

db_manager.py

This module provides a factory function create_db_connection that creates the appropriate database connection object based on the specified service parameter.

  • Supported Services: local, aws, azure, gcp
  • Parameters: host, user, password, database, port, region (for AWS)
db_connection.py

Contains the get_db_connection function, which uses create_db_connection to return the correct connection object and handles errors gracefully.

Database-Specific Connection Classes

Each database type has its own connection class with retry logic and automatic connection handling.

  1. AWSRDSConnection (aws_db.py)

    Manages a connection to an AWS RDS MySQL database and generates an authentication token for secure access.

  2. AzureSQLConnection (azure_db.py)

    Handles connections to Azure SQL Database, supporting automatic retries. Ensure you install the ODBC driver to connect successfully.

  3. GCPMySQLConnection (gcp_db.py)

    Supports MySQL connections on Google Cloud with similar retry and connection management logic.

  4. LocalDBConnection (local_db.py)

    Provides connections to a local MySQL database.

rds_execute.py

Provides a high-level rds_execute function that executes queries across supported databases. It detects the SQL operation type and handles transactions for INSERT, UPDATE, and DELETE operations, committing changes automatically.

  • Operations Supported: SELECT, INSERT, UPDATE, DELETE
  • Parameters:
    • service: Type of database service (local, aws, azure, gcp)
    • query: SQL query to execute
    • params: Parameters for parameterized query (tuple or list of tuples for batch execution)

Error Handling

  • Connection Errors: Retries connection attempts with configurable retry delays for increased robustness.
  • Operational Errors: Prints specific messages on failure and re-raises the error if maximum retries are exceeded.

License

This package 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

clouddatabridge-0.1.12.tar.gz (9.9 kB view details)

Uploaded Source

Built Distribution

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

clouddatabridge-0.1.12-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file clouddatabridge-0.1.12.tar.gz.

File metadata

  • Download URL: clouddatabridge-0.1.12.tar.gz
  • Upload date:
  • Size: 9.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.9.13

File hashes

Hashes for clouddatabridge-0.1.12.tar.gz
Algorithm Hash digest
SHA256 7d13e085fcd2678e940046b9ad45ac49475504546b8e0cfbd0a5b81bcf8a52fd
MD5 5a2a728bd47ec7491e9eec211dcd0c15
BLAKE2b-256 6d08ad247a8033a72bbdb1408e3f3631d0beb7c9b7064b473a938f579781b94b

See more details on using hashes here.

File details

Details for the file clouddatabridge-0.1.12-py3-none-any.whl.

File metadata

File hashes

Hashes for clouddatabridge-0.1.12-py3-none-any.whl
Algorithm Hash digest
SHA256 bfd0ac8d99ac31f5be664a88125e34851f150a089e5db660c53f280dc33cfac3
MD5 baa980c74ac39ee703387581e69523af
BLAKE2b-256 94ab3dc62a5a7f73f163ef642014b3d8cc5533993eed56cb0f904e35e47aeb12

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