红移接口库
redshift-connector的Python项目详细描述
redshift_connector是用于 Python。与pandas和numpy的轻松集成,以及对众多Amazon Redshift特定特性的支持,可以帮助您最大限度地利用数据
支持的Amazon Redshift功能包括:
- IAM身份验证
- 身份提供程序(IdP)身份验证
- 特定于红移的数据类型
这个纯Python连接器实现Python Database API Specification 2.0。在
入门
使用redshift_连接器最简单的方法是通过pip
pip install redshift_connector
pip install 'redshift_connector[full]'
注意:redshift_连接器要求Python>;=3.5
您可以通过克隆此存储库从源安装。在
$ git clone https://github.com/aws/amazon-redshift-python-driver.git
$ cd redshift_connector
$ pip install .
基本示例
^{pr2}$与熊猫的融合
importpandascursor.execute("create Temp table book(bookname varchar,author varchar)")cursor.executemany("insert into book (bookname, author) values (%s, %s)",[('One Hundred Years of Solitude','Gabriel García Márquez'),('A Brief History of Time','Stephen Hawking')])cursor.execute("select * from book")result:pandas.DataFrame=cursor.fetch_dataframe()print(result)>>booknameauthor>>0OneHundredYearsofSolitudeGabrielGarcíaMárquez>>1ABriefHistoryofTimeStephenHawking
与numpy的集成
importnumpycursor.execute("select * from book")result:numpy.ndarray=cursor.fetch_numpy_array()print(result)>>[['One Hundred Years of Solitude''Gabriel García Márquez']>>['A Brief History of Time''Stephen Hawking']]
使用函数查询
cursor.execute("SELECT CURRENT_TIMESTAMP")print(cursor.fetchone())>>[datetime.datetime(2020,10,26,23,3,54,756497,tzinfo=datetime.timezone.utc)]
连接参数
Name | Description | Default Value | Required |
---|---|---|---|
database | String. The name of the database to connect to | Yes | |
user | String. The username to use for authentication | Yes | |
password | String. The password to use for authentication | Yes | |
host | String. The hostname of Amazon Redshift cluster | Yes | |
port | Int. The port number of the Amazon Redshift cluster | 5439 | No |
ssl | Bool. If SSL is enabled | True | No |
iam | Bool. If IAM Authentication is enabled | False | No |
sslmode | String. The security of the connection to Amazon Redshift. ‘verify-ca’ and ‘verify-full’ are supported. | ‘verify-ca’ | No |
idp_response_timeout | Int. The timeout for retrieving SAML assertion from IdP | 120 | No |
listen_port | Int. The listen port IdP will send the SAML assertion to | 7890 | No | |
log_level | Int. The level of logging enabled, increasing in granularity (values [0,4] are valid) | 0 | No |
log_path | String. The file path to the log file | ‘driver.log’ | No |
max_prepared_statements | Int. The maximum number of prepared statements that can be open at once | 1000 | No |
idp_tenant | String. The IdP tenant | None | No |
credentials_provider | String. The IdP that will be used for authenticating with Amazon Redshift. ‘OktaCredentialsProvider’, ‘AzureCredentialsProvider’, ‘BrowserAzureCredentialsProvider’, ‘PingCredentialsProvider’, ‘BrowserSamlCredentialsProvider’, and ‘AdfsCredentialsProvider’ are supported | None | No |
cluster_identifier | String. The cluster identifier of the Amazon Redshift Cluster | None | No |
db_user | String. The user ID to use with Amazon Redshift | None | No |
db_groups | String. A comma-separated list of existing database group names that the DbUser joins for the current session | None | No |
auto_create | Bool. Indicates whether the user should be created if they do not exist | False | No |
allow_db_user_override | Bool. True specifies the driver uses the DbUser value from the SAML assertion while False indicates the value in the DbUser connection parameter is used | False | No |
login_url | String. The SSO Url for the IdP | None | No |
preferred_role | String. The IAM role preferred for the current connection | None | No |
client_secret | String. The client secret from Azure IdP | None | No |
client_id | String. The client id from Azure IdP | None | No |
region | String. The AWS region where the cluster is located | None | No |
app_name | String. The name of the IdP application used for authentication | None | No |
获得帮助
- 在Stack Overflow上提出一个问题,并用redshift连接符标记它
- 使用AWS Support打开支持票证
- 如果您发现了错误,请open an issue
贡献
我们期待与您合作!在提交任何问题或请求之前,请通读CONTRIBUTING。在
运行测试
可以使用pytest test/unit运行测试。这将运行所有单元测试。集成测试需要提供amazonredshift集群的凭证以及test/config.ini中的IdP属性。在
附加资源
- 项目
标签: