Registry / database / chalk-sqlalchemy-redshift

chalk-sqlalchemy-redshift

JSON →
library0.8.15.dev0pypypiunverified

chalk-sqlalchemy-redshift is an Amazon Redshift Dialect for SQLAlchemy, maintained by Chalk. It extends SQLAlchemy to allow seamless interaction with Redshift databases, providing specific type mappings and optimizations for Redshift's nuances. The current version is 0.8.15.dev0, and it generally follows a minor version release cadence driven by Redshift feature updates or SQLAlchemy compatibility changes.

pip install chalk-sqlalchemy-redshift psycopg2-binary
INSTALL
IMPORT
SIG · CHALK-SQLALCHEMY-R
C
chalk-sqlalchemy-redshift
databasepythonv0.8.15.dev0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

RedshiftDialect
✓
The `chalk-sqlalchemy-redshift` package primarily registers itself with SQLAlchemy upon installation. Users typically do not import specific classes or functions from this package directly; SQLAlchemy automatically recognizes the `redshift+...` connection string.

This quickstart demonstrates how to establish a connection to an Amazon Redshift cluster using `chalk-sqlalchemy-redshift` and execute a simple query. It relies on environment variables for sensitive credentials and the `psycopg2-binary` driver. Ensure you have `sqlalchemy` and `psycopg2-binary` installed.

import os from sqlalchemy import create_engine, text from sqlalchemy.exc import OperationalError, ProgrammingError # Get connection details from environment variables for security REDSHIFT_USER = os.environ.get('REDSHIFT_USER', 'your_user') REDSHIFT_PASSWORD = os.environ.get('REDSHIFT_PASSWORD', 'your_password') REDSHIFT_HOST = os.environ.get('REDSHIFT_HOST', 'your-redshift-cluster.abcdef123456.us-east-1.redshift.amazonaws.com') REDSHIFT_PORT = os.environ.get('REDSHIFT_PORT', '5439') REDSHIFT_DB = os.environ.get('REDSHIFT_DB', 'dev') # Construct the Redshift connection string using psycopg2 driver # The 'chalk-sqlalchemy-redshift' package registers the 'redshift+psycopg2' dialect connection_string = ( f"redshift+psycopg2://{REDSHIFT_USER}:{REDSHIFT_PASSWORD}" f"@{REDSHIFT_HOST}:{REDSHIFT_PORT}/{REDSHIFT_DB}" ) if REDSHIFT_USER == 'your_user': print("Please set REDSHIFT_USER, REDSHIFT_PASSWORD, REDSHIFT_HOST, REDSHIFT_PORT, and REDSHIFT_DB environment variables.") print("Skipping quickstart execution.") else: try: engine = create_engine(connection_string) with engine.connect() as connection: # Example: Execute a simple query result = connection.execute(text("SELECT 1 AS test_column")).scalar() print(f"Successfully connected to Redshift. Query result: {result}") # Example: Fetching data data_result = connection.execute(text("SELECT current_database(), current_user()")).fetchall() print(f"Current database: {data_result[0][0]}, Current user: {data_result[0][1]}") except (OperationalError, ProgrammingError) as e: print(f"Error connecting to Redshift or executing query: {e}") print("Please ensure environment variables are set correctly, the Redshift cluster is accessible,") print("and that `psycopg2-binary` is installed (`pip install psycopg2-binary`).") except Exception as e: print(f"An unexpected error occurred: {e}")
Debug
Known issues
breakingThis library is a fork of the original `sqlalchemy-redshift`. While largely compatible, migrating from the original to `chalk-sqlalchemy-redshift` might introduce subtle behavioral differences or changes in supported features.
fix
Thoroughly test your application after switching to `chalk-sqlalchemy-redshift` to ensure compatibility and expected behavior. Review the GitHub repository for any specific changes or enhancements.
affects: All versions when migrating from original `sqlalchemy-redshift`.
gotchaThe dialect requires a compatible database driver like `psycopg2-binary` or `pygresql` to be installed separately. Without it, SQLAlchemy will fail to connect.
fix
Ensure you install the chosen driver alongside the dialect: `pip install chalk-sqlalchemy-redshift psycopg2-binary` (recommended) or `pip install chalk-sqlalchemy-redshift pygresql`.
affects: All versions
gotchaIncorrect connection string format is a common issue. Redshift connection strings often include specific parameters like `sslmode` or IAM credentials, which must be correctly formatted according to SQLAlchemy's URL specification.
fix
Consult the Redshift documentation and SQLAlchemy's engine configuration for the correct connection string format. Example: `redshift+psycopg2://user:pass@host:port/database?sslmode=require`.
affects: All versions
gotchaCompatibility with newer SQLAlchemy core versions can sometimes lag. Using a very recent SQLAlchemy version with an older dialect might lead to unexpected errors or unsupported features.
fix
Check the `chalk-sqlalchemy-redshift` GitHub page for reported compatibility issues with specific SQLAlchemy versions. If encountering problems, try downgrading SQLAlchemy to a version known to be compatible or check if a newer dialect version is available.
affects: All versions when paired with bleeding-edge SQLAlchemy
Upgrade
Version history
0.8.15.dev0latest on PyPI · released Jun 15, 2025
Audit
Dependencies
sqlalchemyrequiredThis is an SQLAlchemy dialect, requiring SQLAlchemy core.
psycopg2-binaryoptionalCommonly used Python adapter for PostgreSQL/Redshift. Required for `redshift+psycopg2` connections.
pygresqloptionalAlternative Python adapter for PostgreSQL/Redshift. Required for `redshift+pygresql` connections.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
1
Resources
chalk-sqlalchemy-redshift — pip install chalk-sqlalchemy-redshift · libregistry