redshift_tool - Elegant data load from Pandas to Redshift
1.Overview
redshift_tool is a python package which is prepared for loading pandas data frame into redshift table. This package is making it easier for bulk uploads, where the procedure for uploading data consists in generating various CSV files, uploading them to an S3 bucket and then calling a copy command on the server, this package helps with all those tasks in encapsulated functions. There are two methods of data copy.
redshift_tool is purely implemented in Python.
2.Installation
3.Usages-Guidelines
- Uses Commands
>>> import redshift_tool >>> redshift_tool.query(data,method,redshift_auth=None,s3_auth=None,schema=None,table=None, primarykey=None,sortkey=None,distkey=None,upsertkey=None)
a). data:- It will take any pandas Data frame.
>>> data= df
>>> method='append/upsert'
>>> redshift_auth= {'db':'database_name','port':port,'user':'user','pswd':'password','host':'host'}
>>> s3_auth = {'accesskey':'aws_access_key','secretkey':'aws_secret_key','bucket':'s3_bucket_name'}
>>> schema='Schema_name'
If target table is already exist, function will be used to copy/usert data into exiting table.
A user can proceed with two steps in case of target table is not exist.
2.1. Use SQL Create staatement to create taget table manualy.
2.2. This libaray can also create target table on the basis of input pandas dataframe columns and datatypes so before using the command make sure all the column names and datatypes of pandas dataframe set properly.
>>> table='table_name'
While creating the table by default, if it is required to define any column as primary key, then pass the column name in a tuple in this parameter.
>>> primarykey=('Primary_Key') or
>>> primarykey=('Primary_Key1','Primary_Key2')
While creating the table by default, if we need to define any column as a sort key, then pass the column name in a tuple in this parameter.
>>> sortkey=('sort_key') or
>>> sortkey=('sort_key1','sort_key2')
>>> distkey=('distribution_key')
>>> upsertkey=('upsertkey') or
>>> upsertkey=('upsertkey1','upsertkey2')
4.Examples
Append or Copy data without primarykey, sortkey, distributionkey
- Eg.
>>> import redshift_tool >>> df= pandas.DataFrame() >>> redshift_tool.query(data=df,method='append', redshift_auth={'db':'database_name','port':port,'user':'user','pswd':'password','host':'host'}, s3_auth={'accesskey':'aws_access_key','secretkey':'aws_secret_key','bucket':'s3_bucket_name'}, schema='shcema_name',table='redshift_table_name')
Append or Copy data with primarykey, sortkey, distributionkey
- Eg.
>>> import redshift_tool >>> df= pandas.DataFrame() >>> redshift_tool.query(data=df,method='append', redshift_auth={'db':'database_name','port':port,'user':'user','pswd':'password','host':'host'}, s3_auth={'accesskey':'aws_access_key','secretkey':'aws_secret_key','bucket':'s3_bucket_name'}, schema='shcema_name',table='redshift_table_name',primarykey=(''primarykey'), sortkey=('sortkey'),distkey=('distributionkey'))
Upsert data without primarykey, sortkey, distributionkey
- Eg.
>>> import redshift_tool >>> df= pandas.DataFrame() >>> redshift_tool.query(data=df,method='append', redshift_auth={'db':'database_name','port':port,'user':'user','pswd':'password','host':'host'}, s3_auth={'accesskey':'aws_access_key','secretkey':'aws_secret_key','bucket':'s3_bucket_name'}, schema='shcema_name',table='redshift_table_name',upsertkey=('upsertkey'))
Upsert data with primarykey, sortkey, distributionkey
- Eg.
>>> import redshift_tool >>> df= pandas.DataFrame() >>> redshift_tool.query(data=df,method='append', redshift_auth={'db':'database_name','port':port,'user':'user','pswd':'password','host':'host'}, s3_auth={'accesskey':'aws_access_key','secretkey':'aws_secret_key','bucket':'s3_bucket_name'}, schema='shcema_name',table='redshift_table_name',primarykey=('primarykey'), sortkey=('sortkey'),distkey=('distributionkey'),upsertkey=('upsertkey'))
5.Support
Operating System
Linux/OSX/Windows
Python Version
2/2.7/3/3.2/3.3/3.4/3.5/3.6/3.7 etc.
6.References
Metadata
Release files for redshift-tool 0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| redshift_tool-0.4.tar.gz | 5.7 kB | Without provenance | Details for redshift_tool-0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| redshift_tool-0.4-py3-none-any.whl | Python 3 | none | any | Details for redshift_tool-0.4-py3-none-any.whl |
Total release size: 12.2 kB
Release files / redshift_tool-0.4.tar.gz
| Download URL | redshift_tool-0.4.tar.gz |
|---|---|
| Size | 5.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
115d9b4f73a3f0bd979fb6ea8f06a796ed9cbd03c905295c7bc12becdac7fb83
|
|
BLAKE2b-256 checksum How to use checksums |
3295e2a68463b8a4e6e0cfef02a18ba832cbc3df55afafe022dea8730f0b7306
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
|
Release files / redshift_tool-0.4-py3-none-any.whl
| Download URL | redshift_tool-0.4-py3-none-any.whl |
|---|---|
| Size | 6.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
ef70b4d7220f94181ed97800d1ae1369037f9deae110b349c85828de15749e9c
|
|
BLAKE2b-256 checksum How to use checksums |
27b7a5001d029e3dfcb3e1270be1627bdf45f4845ed65e92b22718e6da0dc181
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.4.2 requests/2.21.0 setuptools/40.6.3 requests-toolbelt/0.8.0 tqdm/4.28.1 CPython/3.7.1
|
Security for redshift-tool 0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.