Skip to main content

A package for managing local and remote database connections with optional SSH tunneling.

Project description

DBTunnelBridge

DBTunnelBridge is a Python package that simplifies MySQL-compatible database connections with optional SSH tunneling support. It provides a clean, Pythonic interface for managing both local and remote database connections through SSH tunnels, with basic automatic resource management and environment variable integration.

Features

  • 🔌 Simple database connection management
  • 🔒 Secure SSH tunneling support
  • 🔑 Environment variable configuration
  • 🛠 SQLAlchemy integration
  • 📦 Context manager support for automatic resource cleanup
  • 🔄 Automatic port forwarding management

Installation

pip install dbtunnelbridge

Quick Start

Basic Local Connection

from dbtunnelbridge import create_db_connection
# Create a direct database connection
with create_db_connection(
        db_user="your_user",
        db_password="your_password",
        db_host="localhost",
        db_port=3306
        ) as db:
    session = db.get_session()
    # Your database operations here

Create a connection through SSH tunnel

from dbtunnelbridge import create_db_connection

with create_db_connection(
    db_user="your_user",
    db_password="your_password",
    db_host="internal.database.host",
    db_port=3306,
    use_ssh_tunnel=True,
    ssh_host="bastion.example.com",
    ssh_username="ssh_user",
    ssh_pkey="/path/to/private/key"
) as db:
    session = db.get_session()
    # Your database operations here

Environment Variables Support

DBTunnelBridge supports configuration through environment variables:

Database Configuration

  • DB_USER: Database username
  • DB_PASSWORD: Database password
  • DB_HOST: Database host
  • DB_PORT: Database port

SSH Tunnel Configuration

  • USE_SSH_TUNNEL: Enable/disable SSH tunneling ('true'/'false')
  • SSH_HOST: SSH tunnel host
  • SSH_USERNAME: SSH username
  • SSH_PKEY: Path to SSH private key

Advanced Usage

Manual Resource Management

db = create_db_connection(
    db_user="your_user",
    db_password="your_password",
    db_host="localhost",
    db_port=3306
)
try:
    db.create_engine()
    session = db.get_session()
    # Your database operations here
finally:
    db.close_tunnel_if_needed()

Requirements

  • Python 3.10+
  • SQLAlchemy
  • PyMySQL
  • sshtunnel
  • paramiko

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

dbtunnelbridge-0.0.2.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

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

dbtunnelbridge-0.0.2-py3-none-any.whl (2.8 kB view details)

Uploaded Python 3

File details

Details for the file dbtunnelbridge-0.0.2.tar.gz.

File metadata

  • Download URL: dbtunnelbridge-0.0.2.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbtunnelbridge-0.0.2.tar.gz
Algorithm Hash digest
SHA256 05d2e5d1c0a05d289925bbe8a0d2b5b2301a73813813fb6c0b32f2fcdcd791a5
MD5 6ebc39c01dcf361d1cc590969d4ee08e
BLAKE2b-256 5f99c64c9f8060235ceb62bbceb21e7cbd454d4aa563ceabfdc8aaf3db5936e2

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbtunnelbridge-0.0.2.tar.gz:

Publisher: publish.yml on kwilsonmg/DBTunnelBridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file dbtunnelbridge-0.0.2-py3-none-any.whl.

File metadata

  • Download URL: dbtunnelbridge-0.0.2-py3-none-any.whl
  • Upload date:
  • Size: 2.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for dbtunnelbridge-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 ee1d52a4c6ea28d6d2bb81c954d7184c89a6343e544884bd291680c3061de0ed
MD5 19333427785625e6752eddd118cb6472
BLAKE2b-256 16ae66cdcec5ee9a47e785552895e02f5e03093366b519166dc7d53a6c866c1c

See more details on using hashes here.

Provenance

The following attestation bundles were made for dbtunnelbridge-0.0.2-py3-none-any.whl:

Publisher: publish.yml on kwilsonmg/DBTunnelBridge

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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