Access Amazon Redshift data from Python
Amazon Redshift is a fully managed server-less service from the Amazon Web Services that belongs to the category of RDS (Relational Database Systems).
SQL can be used to query data from Redshift. Redshift is typically used for OLAP (Online Analytics and Processing) applications and serves as a powerful data warehouse.
If you as a Developer or Data Scientist or Data Engineer you would like to query data from the Redshift database, you can use tools such as dbeaver.
The other way can be using python and this article will help you for that. Please follow the steps below.
Step 1: Import Dependencies (Install using pip)
import redshift_connector
Step 2: Set Up Configurations
con=redshift_connector.connect(
host='host_name',
database='db_name',
user='user_name',
password='itsasecret'
)
You should provide the following information.
- Host Name
- Database Name
- User Name
- Password
Step 3: Query your Data
with conn.cursor() as cursor:
cursor.execute("Select * from Your_Table_Name")
result: tuple = cursor.fetchall()
print(result)
That was it and it should work. In case of error please try to check for the security groups and inbound rules for your IP.