A SQLAlchemy integration for the Haystack framework.
Project description
sqlalchemy-haystack
A Haystack integration for querying SQL databases via SQLAlchemy.
Provides a SQLAlchemyTableRetriever component that connects to any SQLAlchemy-supported database,
executes a SQL query, and returns results as a Pandas DataFrame and an optional Markdown table.
Installation
pip install sqlalchemy-haystack
You also need to install the appropriate database driver for your backend:
| Backend | Driver package |
|---|---|
| PostgreSQL | psycopg2-binary or psycopg[binary] |
| MySQL / MariaDB | pymysql or mysqlclient |
| SQLite | built-in (no extra package needed) |
| MSSQL | pyodbc |
| Oracle | cx_oracle or oracledb |
Usage
from haystack_integrations.components.retrievers.sqlalchemy import SQLAlchemyTableRetriever
# SQLite in-memory example (no driver needed)
retriever = SQLAlchemyTableRetriever(
drivername="sqlite",
database=":memory:",
init_script=[
"CREATE TABLE products (id INTEGER, name TEXT, price REAL)",
"INSERT INTO products VALUES (1, 'Widget', 9.99)",
"INSERT INTO products VALUES (2, 'Gadget', 19.99)",
],
)
retriever.warm_up()
result = retriever.run(query="SELECT * FROM products WHERE price < 15")
print(result["dataframe"])
print(result["table"])
For PostgreSQL:
from haystack.utils import Secret
retriever = SQLAlchemyTableRetriever(
drivername="postgresql+psycopg2",
host="localhost",
port=5432,
database="mydb",
username="myuser",
password=Secret.from_env_var("DB_PASSWORD"),
)
Security
This component executes raw SQL queries passed at runtime. Keep the following in mind:
- Never pass unsanitised user input directly as a query — this exposes you to SQL injection.
- Use a read-only database user. This is the most effective mitigation. Even if a malicious query is executed, a read-only user cannot modify or delete data.
- Restrict database permissions to the minimum required — specific tables and schemas only,
no DDL privileges (no
CREATE,DROP,ALTER).
Contributing
Refer to the general Contribution Guidelines.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sqlalchemy_haystack-0.1.0.tar.gz.
File metadata
- Download URL: sqlalchemy_haystack-0.1.0.tar.gz
- Upload date:
- Size: 11.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7897b0ecf49913d334e4c0939b65cd0410212d63548fb022890f4cfce8ca6930
|
|
| MD5 |
ba366c4938e1d25b6428009e81ed51ce
|
|
| BLAKE2b-256 |
4a53b84557a577fefe24ff3bddbdc2cada4a73bde00b458659e618d26d57fe27
|
Provenance
The following attestation bundles were made for sqlalchemy_haystack-0.1.0.tar.gz:
Publisher:
CI_pypi_release.yml on deepset-ai/haystack-core-integrations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_haystack-0.1.0.tar.gz -
Subject digest:
7897b0ecf49913d334e4c0939b65cd0410212d63548fb022890f4cfce8ca6930 - Sigstore transparency entry: 1309875508
- Sigstore integration time:
-
Permalink:
deepset-ai/haystack-core-integrations@3a894e2aa83c0bd510f773e65100fce71c796fad -
Branch / Tag:
refs/tags/integrations/sqlalchemy-v0.1.0 - Owner: https://github.com/deepset-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI_pypi_release.yml@3a894e2aa83c0bd510f773e65100fce71c796fad -
Trigger Event:
push
-
Statement type:
File details
Details for the file sqlalchemy_haystack-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sqlalchemy_haystack-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7356c5a2a00c6d3dd3a71576c3b69c298dceda3c3a2bd3c83a73defbf1ec841c
|
|
| MD5 |
8c1ad46e7ea774dc72b48f254390dffb
|
|
| BLAKE2b-256 |
3d1e3e3185031b23477d61da0401c2ac16c4b38b27ed1e2033c6c31e539cca96
|
Provenance
The following attestation bundles were made for sqlalchemy_haystack-0.1.0-py3-none-any.whl:
Publisher:
CI_pypi_release.yml on deepset-ai/haystack-core-integrations
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
sqlalchemy_haystack-0.1.0-py3-none-any.whl -
Subject digest:
7356c5a2a00c6d3dd3a71576c3b69c298dceda3c3a2bd3c83a73defbf1ec841c - Sigstore transparency entry: 1309875654
- Sigstore integration time:
-
Permalink:
deepset-ai/haystack-core-integrations@3a894e2aa83c0bd510f773e65100fce71c796fad -
Branch / Tag:
refs/tags/integrations/sqlalchemy-v0.1.0 - Owner: https://github.com/deepset-ai
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
CI_pypi_release.yml@3a894e2aa83c0bd510f773e65100fce71c796fad -
Trigger Event:
push
-
Statement type: