Skip to main content

A command tool and library to connect to databases with minimal fuss.

To install:

$ pip install tunneler

You will probably also need the database drivers for your preferred database. To install the postgres ones automatically when you install tunneler, do this:

$ pip install tunneler[pg]

To run:

$ tunneler name_of_task name_of_connection

As the above command shows, there are two concepts to understand when running tunneler, connections and tasks.

Define connections in a connections.yaml file in your current directory, as follows:

prod:
  remote_host: publicjumpboxservername
  ssh_username: username
  ssh_pkey: |
    -----BEGIN RSA PRIVATE KEY-----
    .......................................
    .......................................
    -----END RSA PRIVATE KEY-----
  private_dburl: postgres://username:password@privatedbservername/databasename
  local_port: 5433

dev:
  .....

You can also specify an ssh_config variable in the config. tunneler will then use the values from that hosts ssh config. An example:

prod:
  ssh_config: prod-jumpbox
  private_dburl: postgres://username:password@privatedbservername/databasename
  local_port: 5433

dev:
  .....

This will use the remote host/username/private key specified in your existing ssh config so you don’t need to repeat them in the config file

Tunneler will use this information to set up a local tunneled post where you can access this database directly.

A connection URL to this local port will then be provided to each task.

There are three inbuilt tasks:

  • test_connection (run this one to check your config is correct)

  • do_full_pg_dump (assumes you have pg_dump installed)

  • do_schema_pg_dump (also assumes you have pg_dump installed)

So for example to dump the production schema we’d run the following command:

$ tunneler do_schema_pg_dump prod

Custom tasks

Want to define your own tasks? Simply create a tasks.py file (or module) in the current directory.

Define a top level method in this file that accepts a connection url, and that method name will be available as a task.

For instance, the test connection task could be re-implemented as follows:

from sqlbag import S

def test_connection_custom(dburl):
    with S(dburl) as s:
        s.execute('select 1')

You’d then run this as follows:

$ tunneler test_connection_custom prod

Pretty simple.

Metadata

Release files for tunneler 0.1.1490760674

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

Source distribution (sdist)

Source distribution for tunneler 0.1.1490760674
File Size Uploaded
tunneler-0.1.1490760674.tar.gz 4.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for tunneler 0.1.1490760674
File Interpreter ABI Platform
tunneler-0.1.1490760674-py2.py3-none-any.whl Python 3, Python 2 none any Details

Total release size: 12.1 kB

Release files / tunneler-0.1.1490760674.tar.gz

Download URL tunneler-0.1.1490760674.tar.gz
Size 4.5 kB
Tags Source
SHA-256 checksum
How to use checksums
15112345f167216891a9db4493ec298eab980558a47b48079614d4fb3fcec9d6
BLAKE2b-256 checksum
How to use checksums
b16b077a59c6532b948a4ccee815e52c93769e87c9a92e906c1ce8a707f3f536
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / tunneler-0.1.1490760674-py2.py3-none-any.whl

Download URL tunneler-0.1.1490760674-py2.py3-none-any.whl
Size 7.7 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
5bc93dd2786f0cd4e61f6cbaedc92ffa83c45bbe0276862beb58344c1cb94f86
BLAKE2b-256 checksum
How to use checksums
e433b3ff64979e212877dad5fb9308c052295d18ea1e214d32dac2ea54da6a72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.1.1490760674 This release

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