Amazon Redshift Python Connector
raw JSON → 2.1.12 verified Tue May 12 auth: no python install: verified quickstart: verified
redshift-connector is the official Amazon Redshift connector for Python, implementing the Python Database API Specification 2.0. It provides easy integration with data science libraries like pandas and numpy, and supports Redshift-specific features such as IAM and Identity Provider (IdP) authentication. The library is actively maintained with frequent minor releases, currently at version 2.1.12.
pip install redshift-connector Common errors
error ModuleNotFoundError: No module named 'redshift_connector' ↓
cause The 'redshift-connector' package is not installed in the Python environment where the script is being executed.
fix
pip install redshift-connector
error redshift_connector.Error.OperationalError: could not connect to server: Connection refused ↓
cause The Redshift cluster is unreachable, likely due to incorrect host/port in the connection string, network configuration, or firewall rules blocking access.
fix
Ensure the host, port, user, password, and database parameters passed to redshift_connector.connect() are correct, and verify network access (security groups, NACLs) to the Redshift cluster from your environment.
error redshift_connector.Error.DatabaseError: FATAL: password authentication failed for user "your_user" ↓
cause The provided username or password for connecting to Redshift is incorrect, or the specified user lacks the necessary database permissions.
fix
Verify the username and password used in the redshift_connector.connect() call are correct and that the user has appropriate permissions in Redshift.
error redshift_connector.Error.DatabaseError: InvalidToken ↓
cause The AWS IAM credentials used for authentication are invalid, expired, or the associated IAM role lacks the 'redshift:GetClusterCredentials' permission.
fix
Ensure your AWS credentials are valid and correctly configured for IAM authentication with redshift_connector.connect(), and confirm the IAM role has 'redshift:GetClusterCredentials' permission.
error OperationalError: Could not connect to host=..., port=...: connection timeout ↓
cause The Python environment cannot establish a network connection to the specified Redshift host and port, often due to incorrect host/port, network configuration, or firewall rules.
fix
Verify the Redshift cluster's hostname and port. Ensure your security groups, network ACLs, and local firewalls allow outbound connections to the Redshift cluster on the specified port.
Warnings
breaking A security vulnerability (CVE-2025-5279) existed in versions 2.0.872 through 2.1.6, where the `BrowserAzureOAuth2CredentialsProvider` plugin skipped SSL certificate validation for the Identity Provider (IdP). This could allow an actor to intercept token exchange. ↓
fix Upgrade to `redshift-connector` version 2.1.7 or later to address this issue.
gotcha Autocommit is `OFF` by default, adhering to the Python DB-API specification. Transactions must be explicitly committed for changes to persist. ↓
fix Set `conn.autocommit = True` after connecting, or explicitly call `conn.commit()` after executing statements that modify data.
gotcha Network connectivity issues, including timeouts, are common, especially when connecting from outside an Amazon EC2 instance or running long-duration queries. This can be due to firewall rules, VPC configurations, or client-side TCP/IP timeout settings. ↓
fix Ensure Redshift cluster security groups and network ACLs allow inbound/outbound traffic on the Redshift port (default 5439). Increase client system TCP/IP timeout values for long-running queries or idle connections.
gotcha For loading large amounts of data into Redshift, using individual `INSERT` statements can be prohibitively slow and expensive. ↓
fix Strongly prefer using the `COPY` command with Amazon S3 staging for bulk data loads. The `redshift-connector` supports this method.
deprecated Amazon Redshift is ending support for creating new Python User-Defined Functions (UDFs) starting with Patch 198. Existing Python UDFs will continue to function but will be fully unsupported after June 30, 2026. ↓
fix Migrate existing Python UDFs to alternative solutions before June 30, 2026. For new functionality, consider SQL UDFs or other data processing patterns.
Install
pip install redshift-connector[full] Install compatibility verified last tested: 2026-05-12
python os / libc variant status wheel install import disk
3.10 alpine (musl) redshift-connector wheel - 0.93s 72.5M
3.10 alpine (musl) full wheel - 0.85s 215.7M
3.10 alpine (musl) redshift-connector - - 0.83s 72.1M
3.10 alpine (musl) full - - 0.81s 215.2M
3.10 slim (glibc) redshift-connector wheel 6.3s 0.67s 73M
3.10 slim (glibc) full wheel 12.0s 0.65s 208M
3.10 slim (glibc) redshift-connector - - 0.61s 73M
3.10 slim (glibc) full - - 0.60s 208M
3.11 alpine (musl) redshift-connector wheel - 1.03s 76.4M
3.11 alpine (musl) full wheel - 1.04s 232.9M
3.11 alpine (musl) redshift-connector - - 1.17s 75.9M
3.11 alpine (musl) full - - 1.16s 232.4M
3.11 slim (glibc) redshift-connector wheel 5.7s 1.01s 77M
3.11 slim (glibc) full wheel 11.4s 1.02s 225M
3.11 slim (glibc) redshift-connector - - 0.89s 76M
3.11 slim (glibc) full - - 0.90s 224M
3.12 alpine (musl) redshift-connector wheel - 1.05s 76.8M
3.12 alpine (musl) full wheel - 1.04s 226.8M
3.12 alpine (musl) redshift-connector - - 1.04s 76.4M
3.12 alpine (musl) full - - 1.02s 226.3M
3.12 slim (glibc) redshift-connector wheel 5.9s 1.07s 77M
3.12 slim (glibc) full wheel 11.7s 1.03s 219M
3.12 slim (glibc) redshift-connector - - 1.02s 77M
3.12 slim (glibc) full - - 1.01s 218M
3.13 alpine (musl) redshift-connector wheel - 0.93s 76.5M
3.13 alpine (musl) full wheel - 0.89s 225.8M
3.13 alpine (musl) redshift-connector - - 1.01s 76.0M
3.13 alpine (musl) full - - 1.00s 225.1M
3.13 slim (glibc) redshift-connector wheel 5.5s 0.94s 77M
3.13 slim (glibc) full wheel 11.1s 0.86s 218M
3.13 slim (glibc) redshift-connector - - 1.03s 76M
3.13 slim (glibc) full - - 1.00s 217M
3.9 alpine (musl) redshift-connector wheel - 0.73s 71.7M
3.9 alpine (musl) full wheel - 0.76s 223.1M
3.9 alpine (musl) redshift-connector - - 0.74s 71.4M
3.9 alpine (musl) full - - 0.77s 222.9M
3.9 slim (glibc) redshift-connector wheel 7.1s 0.70s 72M
3.9 slim (glibc) full wheel 14.3s 0.66s 218M
3.9 slim (glibc) redshift-connector - - 0.64s 72M
3.9 slim (glibc) full - - 0.61s 218M
Imports
- redshift_connector
import redshift_connector
Quickstart verified last tested: 2026-04-24
import redshift_connector
import os
try:
# Connect to Redshift cluster using environment variables for credentials
conn = redshift_connector.connect(
host=os.environ.get('REDSHIFT_HOST', 'your-redshift-cluster.example.com'),
database=os.environ.get('REDSHIFT_DB', 'dev'),
port=int(os.environ.get('REDSHIFT_PORT', '5439')),
user=os.environ.get('REDSHIFT_USER', 'awsuser'),
password=os.environ.get('REDSHIFT_PASSWORD', 'your_password_here')
)
# Create a Cursor object
cursor = conn.cursor()
# Execute a query
cursor.execute("SELECT 1 as id, 'Hello, Redshift!' as message;")
# Retrieve the query result set
result = cursor.fetchall()
print("Query Result:", result)
# Close the cursor and connection
cursor.close()
conn.close()
except Exception as e:
print(f"An error occurred: {e}")