Extract data from Amazon Redshift into Semantica with password/native or IAM-role authentication, using the PostgreSQL-compatible wire protocol.

Installation

redshift-connector is an optional dependency. A plain pip install semantica never pulls it in, and import semantica.ingest never loads it eagerly — the SDK is imported only when you first use RedshiftConnector or RedshiftIngestor.
This connector uses the Redshift database wire protocol for read ingestion. COPY, UNLOAD, S3 integration, Spectrum external tables, and the Redshift Data API are outside the current scope of this integration.

Basic Usage

Use environment variables (or a .env file with python-dotenv) to keep credentials out of source code. RedshiftIngestor() with no arguments reads from REDSHIFT_* environment variables automatically.

Authentication

The standard Redshift database username and password:
Required environment variables:

Environment Variables

All constructor parameters have REDSHIFT_* environment-variable fallbacks. Explicit constructor values always take precedence.

Querying

Ingest a table

Schema, filters, and pagination

where and order_by accept raw SQL fragments and must be trusted, operator-controlled input. Do not pass raw end-user strings here. They are validated against a blocklist that rejects statement separators, UNION, DML/DDL keywords, and time-based injection patterns, but this is not a full parser.

Custom SQL

Parameterized queries

Use %s placeholders (DB-API 2.0 format paramstyle, which is the default for redshift-connector):

Batch fetching for large result sets

Use batch_size to control the driver fetch size — rows are fetched from the server in chunks of that size rather than all at once, and each chunk is converted immediately before the next is requested:
batch_size controls how many rows the driver reads from Redshift per round-trip. The returned RedshiftData.data list still contains all matching rows; use LIMIT/OFFSET in the query itself if you need to cap the total result size.

Schema Discovery

List base tables in a schema

Views are excluded; only base tables are returned.

Inspect column metadata

Each column dict contains: primary_keys is a list of column-name strings (empty list when no primary key is defined).

Export as Semantica Documents

Convert ingested rows to the document format that GraphBuilder consumes:
ID resolution: str(row.get(id_field, row_index)) — the integer row index is used as a deterministic fallback when the id_field column is absent. Text when text_fields is provided: each non-None field value is converted to a string and joined with a single space. Text when text_fields=None: only columns whose values are already str type are joined. Integer, float, boolean, and None values are excluded, matching the Snowflake and Databricks connector behavior. Pass the documents directly to GraphBuilder:

Context Manager

Prefer the context manager for jobs that run multiple queries — it opens one connection on entry and closes it on exit, so every call inside the with block reuses the same authenticated session:
Standalone calls (without with) open and close a transient connection per call.

Connection Test

See Also