How to connect redshift with python?

Hardik Patel
2 min readJan 21, 2023

Prerequisites

  • vscode
  • aws account
  • redshift cluster with public access

setup python virtual environment,

python -m venv rd-venv

I am using windows,

source rd-venv/Scripts/activate

Now we are going to install dependency to connect redshift cluster. As we know redshift is flavor of PostgreSQL so we are going to install psycopg2 library package before connecting to redshift cluster using python. Also we install additional library boto3 and jupyterlab as well.

pip3.10.exe install psycopg2-binary
pip3.10.exe install boto3
pip3.10.exe install jupyterlab

launch jupyterlab from terminal just type,

jupyter lab

and its opened in your default browser,

follow below link before execute further query,

Hence, we have seen that we are successfully able to connect and query the redshift cluster using python from our local.

If you found this guide helpful then do click on 👏 the button and also feel free to drop a comment.

Follow for more stories like this 😊

--

--