Skip to main content

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,
    is_proxy=False,
    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: is_proxy, 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.

Metadata

Release files for cloud-db-service 0.1.7

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cloud-db-service 0.1.7
File Size Uploaded
cloud_db_service-0.1.7.tar.gz 11.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cloud-db-service 0.1.7
File Interpreter ABI Platform
cloud_db_service-0.1.7-py3-none-any.whl Python 3 none any Details

Total release size: 25.5 kB

Release files / cloud_db_service-0.1.7.tar.gz

Download URL cloud_db_service-0.1.7.tar.gz
Size 11.4 kB
Tags Source
SHA-256 checksum
How to use checksums
7934e4901eb535f2796db4a4aff64714ff1201418a80a223a0388d0cc4f01a9d
BLAKE2b-256 checksum
How to use checksums
ede9dbff1f6cd49e7f165b485717054e1d6b010c017a6f6db1c12948c6095b77
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Release files / cloud_db_service-0.1.7-py3-none-any.whl

Download URL cloud_db_service-0.1.7-py3-none-any.whl
Size 14.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1dbe7efa5e0bb019f5797f28b9fc5cc7e7b4581c37c10d2dd55687ac9e7c3d42
BLAKE2b-256 checksum
How to use checksums
b97dddf4561d9f2577b6509e2d9463d32690189c72767a34ac0b0634182868af
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.7

Release history Release notifications | RSS feed

This release

0.1.7 This release

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page