Redshift¶
Overview¶
The Redshift class allows you to interact with an Amazon Redshift relational batabase. The Redshift Connector utilizes the psycopg2 python package to connect to the database.
In order to instantiate the class you must pass valid kwargs or store the following environmental variables:
'REDSHIFT_USERNAME''REDSHIFT_PASSWORD''REDSHIFT_HOST''REDSHIFT_DB''REDSHIFT_PORT'
Note
- S3 Credentials
Redshift only allows data to be copied to the database via S3. As such, you need to include AWS S3 credentials in your copy methods or, better yet, store them as environmental variables. In addition, you’ll need to provide the env var S3_TEMP_BUCKET, which is the bucket name used for storing data en route to Redshift.
- Whitelisting
Remember to ensure that the IP address from which you are connecting has been whitelisted.
Quickstart¶
Query the Database
from parsons import Redshift
rs = Redshift()
table = rs.query('select * from tmc_scratch.test_data')
Copy a Parsons Table to the Database
from parsons import Redshift
rs = Redshift()
table = rs.copy(tbl, 'tmc_scratch.test_table', if_exists='drop')
All of the standard copy options can be passed as kwargs. See the copy() method for all
options.