Skip to main content
bgtunnel - Initiate SSH tunnels in the background
Useful when you need to connect to a database only accessible through
another ssh-enabled host. It works by opening a port forwarding ssh
connection in the background, using threads. The connection(s) are
automatically closed when the process exits, or when explicitly calling
the `close` method of the returned SSHTunnelForwarderThread object.

Notes on default values
-----------------------

* Bind address and host address defaults to "127.0.0.1"
* SSH port defaults to 22
* Bind port defaults to picking a random available one, accessible from the
object returned by the `open` function

Usage examples
--------------

# Enable forwarding for a MS SQL server running on the remote SSH host
>>> import bgtunnel
>>> forwarder = bgtunnel.open(ssh_user='manager', ssh_address='1.2.3.4',
... host_port=1433)
>>> print(forwarder.bind_port)
59432
>>> import somesqlpkg
>>> conn = somesqlpkg.connect('mssql://myuser:mypassword@localhost:' +
forwarder.port)

# Enable forwarding for an old AS400 DB2 server accessible only via
# the remote SSH host. Multiple ports need to be opened.
>>> import bgtunnel
>>> ports = [446, 449] + range(8470, 8477)
>>> forwarders = []
>>> for port in ports:
... forwarders.append(bgtunnel.open(ssh_user='manager',
... ssh_address='1.2.3.4',
host_address='192.168.0.5',
... host_port=port, bind_port=port))
>>> print('
'.join(f.bind_port for f in forwarders))
446
449
8470
8471
8472
8473
8474
8475
8476
>>> import somesqlpkg
>>> conn = somesqlpkg.connect('mssql://myuser:mypassword@localhost:446')

Metadata

Release files for bgtunnel 0.4.1

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

Source distribution (sdist)

Source distribution for bgtunnel 0.4.1
File Size Uploaded
bgtunnel-0.4.1.tar.gz 7.3 kB Details

Built distribution (wheel)

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

Total release size: 15.7 kB

Release files / bgtunnel-0.4.1.tar.gz

Download URL bgtunnel-0.4.1.tar.gz
Size 7.3 kB
Tags Source
SHA-256 checksum
How to use checksums
baa1fde61093cad1619a3ba8af3e1c6a3d3363b43ad8afaa26a4718c612e41ee
BLAKE2b-256 checksum
How to use checksums
f1c05bc59657f87eb17b2f8b9f2edacab12d9ce58a653b7f03b053360a3ffbe7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release files / bgtunnel-0.4.1-py2.py3-none-any.whl

Download URL bgtunnel-0.4.1-py2.py3-none-any.whl
Size 8.4 kB
Tags Python 2 Python 3
SHA-256 checksum
How to use checksums
485f1c964a388d811a4590eeede012db52596c7803ac3568096cbdf3090c5b72
BLAKE2b-256 checksum
How to use checksums
d2d5635728d2d8fe0c1e2d0e4aedb52fa785dae80590e3d16988c9abf8e775ad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

0.4.1 This release

2 release files

0.4.0

1 release file

0.3.8

1 release file

0.3.7

1 release file

0.3.6

1 release file

0.3.5

1 release file

0.3.4

1 release file

0.3.3

1 release file

0.3.2

1 release file

0.3.1

1 release file

0.3.0

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

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