Connecting to PostgreSQL using Python
Introduction
Sometimes connecting to the database directly using Python (or other programming language) is the best way forward. Some sample code is available below
Connecting to Canopy Data Eco-System using Python
import psycopg2 from psycopg2 import extras # database credentials (please replace with credentials provided by Canopy) database_host_url = 'abcd.amazon.com' database_name = 'abcd1234' database_username = 'polo5678' database_pwd = 'password' # Login to PostgreSQL database canopy_postgresql_conn = psycopg2.connect(dbname=database_name, user=database_username, host=database_host_url, password=database_pwd) canopy_postgresql_conn.autocommit = True with canopy_postgresql_conn.cursor(cursor_factory=psycopg2.extras.DictCursor) as temp_cursor: temp_cursor.execute("select * from consolidated_holdings limit 5;") results = temp_cursor.fetchall() for row in results: print (row)