
Postgres ssh tunnel code#
In this article, I will share with you two code snippets (one for psycopg2 and the other for sqlalchemy) that I created to solve the problem. This is what I thought the first time I discovered SSH even existed and it took me a while to digest the idea of having to connect via a tunnel every time I wished to query a PostGreSQL database, both through a DMBS, or via a Python script. “This is annoying…Now I will need to write another bullet-proof script to replace the ones I have used for years…” But what if your company has implemented SSH tunnelling as an additional encryption layer?

generating and engine through the sqlalchemy package.Īs long as you have valid credentials, you can establish a connection with few lines of code.creating a connection using pycopg2 package.Python offers at least two straightforward ways to interact with a PostgreSQL database: *UP TO 25% DISCOUNT ON UDACITY COURSES IN FEB 2022 USING CODE PROMOTION25** Introduction

Do you wish to become a Data Engineer and advance your career in 2022? Have a look at Udacity’s on-demand Data Engineering Nanodegree and take advantage of the following special discount code for Feb 2022:
