红移接口库

redshift-connector的Python项目详细描述


redshift_connector是用于 Python。与pandasnumpy的轻松集成,以及对众多Amazon Redshift特定特性的支持,可以帮助您最大限度地利用数据

支持的Amazon Redshift功能包括:

  • IAM身份验证
  • 身份提供程序(IdP)身份验证
  • 特定于红移的数据类型

这个纯Python连接器实现Python Database API Specification 2.0。在

入门

使用redshift_连接器最简单的方法是通过pip

pip install redshift_connector

对于pandasnumpy支持,请按如下所示进行安装:

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)]

连接参数

NameDescriptionDefault ValueRequired
databaseString. The name of the database to connect toYes
userString. The username to use for authenticationYes
passwordString. The password to use for authenticationYes
hostString. The hostname of Amazon Redshift clusterYes
portInt. The port number of the Amazon Redshift cluster5439No
sslBool. If SSL is enabledTrueNo
iamBool. If IAM Authentication is enabledFalseNo
sslmodeString. The security of the connection to Amazon Redshift. ‘verify-ca’ and ‘verify-full’ are supported.‘verify-ca’No
idp_response_timeoutInt. The timeout for retrieving SAML assertion from IdP120No
listen_port | Int. The listen port IdP will send the SAML assertion to7890No
log_levelInt. The level of logging enabled, increasing in granularity (values [0,4] are valid)0No
log_pathString. The file path to the log file‘driver.log’No
max_prepared_statementsInt. The maximum number of prepared statements that can be open at once1000No
idp_tenantString. The IdP tenantNoneNo
credentials_providerString. The IdP that will be used for authenticating with Amazon Redshift. ‘OktaCredentialsProvider’, ‘AzureCredentialsProvider’, ‘BrowserAzureCredentialsProvider’, ‘PingCredentialsProvider’, ‘BrowserSamlCredentialsProvider’, and ‘AdfsCredentialsProvider’ are supportedNoneNo
cluster_identifierString. The cluster identifier of the Amazon Redshift ClusterNoneNo
db_userString. The user ID to use with Amazon RedshiftNoneNo
db_groupsString. A comma-separated list of existing database group names that the DbUser joins for the current sessionNoneNo
auto_createBool. Indicates whether the user should be created if they do not existFalseNo
allow_db_user_overrideBool. True specifies the driver uses the DbUser value from the SAML assertion while False indicates the value in the DbUser connection parameter is usedFalseNo
login_urlString. The SSO Url for the IdPNoneNo
preferred_roleString. The IAM role preferred for the current connectionNoneNo
client_secretString. The client secret from Azure IdPNoneNo
client_idString. The client id from Azure IdPNoneNo
regionString. The AWS region where the cluster is locatedNoneNo
app_nameString. The name of the IdP application used for authenticationNoneNo

获得帮助

贡献

我们期待与您合作!在提交任何问题或请求之前,请通读CONTRIBUTING。在

运行测试

可以使用pytest test/unit运行测试。这将运行所有单元测试。集成测试需要提供amazonredshift集群的凭证以及test/config.ini中的IdP属性。在

附加资源

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
使用jaxb2annotateplugin和XJC工具的java自定义注释   java组织。xeustechnologies。jcl无法加载WstxInputFactory类   java JUnit在格式化字符串上比较失败   java Bukkit配置部分getKeys   如何关闭Java流?   java Struts2正则表达式配置   链式事务注释的java奇怪行为   java在两个JButton之间使用变量   java签署APK时内容会发生什么变化?   java LWJGL:Slick:3D世界中的绘图字体   如何分解Java数组?   在Java MySql中处理多个过滤器   java如何在Firebase数据库中跳过初始OnChildaded事件触发   java如何在PreviewView中使用CameraX?   在子类#中重写父类后访问父类原始方法的java已解决   java找不到类型的属性   游戏框架游戏!框架+Java