sqlalchemy-haystack 0.1.0__tar.gz → 1.0.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,25 @@
1
+ # Changelog
2
+
3
+ ## [integrations/sqlalchemy-v1.0.0] - 2026-10-16
4
+
5
+ ### 🐛 Bug Fixes
6
+
7
+ - Fix new issues raised by ruff 0.16.0 (#3670)
8
+
9
+ ### 🧪 Testing
10
+
11
+ - Test compatible integrations with Python 3.15; update pyproject (#4104)
12
+
13
+ ### 🧹 Chores
14
+
15
+ - Re-standardize READMEs (#3768)
16
+ - [**breaking**] Drop Python 3.10 support (#4105)
17
+
18
+
19
+ ## [integrations/sqlalchemy-v0.1.0] - 2026-04-15
20
+
21
+ ### 🚀 Features
22
+
23
+ - Adding an `SQLAlchemy` integration (#3098)
24
+
25
+ <!-- generated by git-cliff -->
@@ -0,0 +1,39 @@
1
+ Metadata-Version: 2.5
2
+ Name: sqlalchemy-haystack
3
+ Version: 1.0.1
4
+ Summary: A SQLAlchemy integration for the Haystack framework.
5
+ Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/sqlalchemy#readme
6
+ Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
7
+ Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/sqlalchemy
8
+ Author-email: deepset GmbH <info@deepset.ai>
9
+ License-Expression: Apache-2.0
10
+ License-File: LICENSE.txt
11
+ Classifier: Development Status :: 4 - Beta
12
+ Classifier: License :: OSI Approved :: Apache Software License
13
+ Classifier: Programming Language :: Python
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Classifier: Programming Language :: Python :: 3.15
19
+ Classifier: Programming Language :: Python :: Implementation :: CPython
20
+ Classifier: Programming Language :: Python :: Implementation :: PyPy
21
+ Requires-Python: >=3.11
22
+ Requires-Dist: haystack-ai>=2.22.0
23
+ Requires-Dist: pandas>=3.0.0
24
+ Requires-Dist: sqlalchemy>=2.0.36
25
+ Description-Content-Type: text/markdown
26
+
27
+ # sqlalchemy-haystack
28
+
29
+ [![PyPI - Version](https://img.shields.io/pypi/v/sqlalchemy-haystack.svg)](https://pypi.org/project/sqlalchemy-haystack)
30
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlalchemy-haystack.svg)](https://pypi.org/project/sqlalchemy-haystack)
31
+
32
+ - [Integration page](https://haystack.deepset.ai/integrations/sqlalchemy)
33
+ - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/sqlalchemy/CHANGELOG.md)
34
+
35
+ ---
36
+
37
+ ## Contributing
38
+
39
+ Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
@@ -0,0 +1,13 @@
1
+ # sqlalchemy-haystack
2
+
3
+ [![PyPI - Version](https://img.shields.io/pypi/v/sqlalchemy-haystack.svg)](https://pypi.org/project/sqlalchemy-haystack)
4
+ [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlalchemy-haystack.svg)](https://pypi.org/project/sqlalchemy-haystack)
5
+
6
+ - [Integration page](https://haystack.deepset.ai/integrations/sqlalchemy)
7
+ - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/sqlalchemy/CHANGELOG.md)
8
+
9
+ ---
10
+
11
+ ## Contributing
12
+
13
+ Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
@@ -7,7 +7,7 @@ name = "sqlalchemy-haystack"
7
7
  dynamic = ["version"]
8
8
  description = 'A SQLAlchemy integration for the Haystack framework.'
9
9
  readme = "README.md"
10
- requires-python = ">=3.10"
10
+ requires-python = ">=3.11"
11
11
  license = "Apache-2.0"
12
12
  keywords = []
13
13
  authors = [{ name = "deepset GmbH", email = "info@deepset.ai" }]
@@ -15,19 +15,18 @@ classifiers = [
15
15
  "License :: OSI Approved :: Apache Software License",
16
16
  "Development Status :: 4 - Beta",
17
17
  "Programming Language :: Python",
18
- "Programming Language :: Python :: 3.10",
19
18
  "Programming Language :: Python :: 3.11",
20
19
  "Programming Language :: Python :: 3.12",
21
20
  "Programming Language :: Python :: 3.13",
22
21
  "Programming Language :: Python :: 3.14",
22
+ "Programming Language :: Python :: 3.15",
23
23
  "Programming Language :: Python :: Implementation :: CPython",
24
24
  "Programming Language :: Python :: Implementation :: PyPy",
25
25
  ]
26
26
  dependencies = [
27
27
  "haystack-ai>=2.22.0",
28
28
  "sqlalchemy>=2.0.36",
29
- "pandas>=2.2.3; python_version < '3.11'",
30
- "pandas>=3.0.0; python_version >= '3.11'",
29
+ "pandas>=3.0.0",
31
30
  ]
32
31
 
33
32
  [project.urls]
@@ -137,6 +136,7 @@ ignore = [
137
136
  "PLR0912",
138
137
  "PLR0913",
139
138
  "PLR0915",
139
+ "PLR0917",
140
140
  # Ignore SQL injection warning (user-provided queries are expected)
141
141
  "S608",
142
142
  # Unused method argument
@@ -8,7 +8,7 @@ from haystack import component, default_from_dict, default_to_dict, logging
8
8
  from haystack.utils import Secret, deserialize_secrets_inplace
9
9
  from pandas import DataFrame
10
10
 
11
- from sqlalchemy import create_engine, text
11
+ from sqlalchemy import create_engine
12
12
  from sqlalchemy.engine import URL, Engine
13
13
  from sqlalchemy.exc import SQLAlchemyError
14
14
  from sqlalchemy.pool import StaticPool
@@ -18,6 +18,11 @@ logger = logging.getLogger(__name__)
18
18
  MAX_SYS_ROWS = 10_000
19
19
 
20
20
 
21
+ # Run SQL strings as written: `text()` would treat ":name" (even inside string literals) as a bind parameter.
22
+ # `no_parameters` stops drivers such as psycopg2 from treating "%" as a parameter marker.
23
+ _RAW_SQL_OPTIONS = {"no_parameters": True}
24
+
25
+
21
26
  @component
22
27
  class SQLAlchemyTableRetriever:
23
28
  """
@@ -104,7 +109,7 @@ class SQLAlchemyTableRetriever:
104
109
  for stmt in self.init_script:
105
110
  stripped = stmt.strip()
106
111
  if stripped:
107
- conn.execute(text(stripped))
112
+ conn.exec_driver_sql(stripped, execution_options=_RAW_SQL_OPTIONS)
108
113
  conn.commit()
109
114
 
110
115
  self._warmed_up = True
@@ -174,7 +179,7 @@ class SQLAlchemyTableRetriever:
174
179
 
175
180
  try:
176
181
  with self._engine.connect() as conn:
177
- result = conn.execute(text(query))
182
+ result = conn.exec_driver_sql(query, execution_options=_RAW_SQL_OPTIONS)
178
183
  rows = result.fetchmany(MAX_SYS_ROWS)
179
184
  columns = list(result.keys())
180
185
  df = DataFrame(rows, columns=columns)
@@ -84,8 +84,10 @@ class TestSQLAlchemyTableRetrieverRun:
84
84
  @pytest.fixture()
85
85
  def retriever_with_data(self):
86
86
  init_sql = [
87
- "CREATE TABLE employees (id INTEGER PRIMARY KEY, name TEXT NOT NULL,"
88
- " department TEXT NOT NULL, salary INTEGER NOT NULL)",
87
+ (
88
+ "CREATE TABLE employees (id INTEGER PRIMARY KEY, name TEXT NOT NULL,"
89
+ " department TEXT NOT NULL, salary INTEGER NOT NULL)"
90
+ ),
89
91
  "INSERT INTO employees VALUES (1, 'Alice', 'Engineering', 95000)",
90
92
  "INSERT INTO employees VALUES (2, 'Bob', 'Marketing', 72000)",
91
93
  "INSERT INTO employees VALUES (3, 'Carol', 'Engineering', 88000)",
@@ -171,3 +173,19 @@ class TestSQLAlchemyTableRetrieverRun:
171
173
  result = retriever.run(query="SELECT 1 AS x")
172
174
  assert retriever._warmed_up
173
175
  assert not result["dataframe"].empty
176
+
177
+ def test_colons_in_string_literals_are_not_bind_parameters(self):
178
+ retriever = SQLAlchemyTableRetriever(
179
+ drivername="sqlite",
180
+ database=":memory:",
181
+ init_script=[
182
+ "CREATE TABLE notes (id INTEGER, body TEXT)",
183
+ "INSERT INTO notes VALUES (1, 'see :ref'), (2, '{\"k\":1}')",
184
+ ],
185
+ )
186
+ retriever.warm_up()
187
+
188
+ result = retriever.run(query="SELECT id FROM notes WHERE body = 'see :ref' OR body = '{\"k\":1}' ORDER BY id")
189
+
190
+ assert result["error"] == ""
191
+ assert result["dataframe"]["id"].tolist() == [1, 2]
@@ -1,7 +0,0 @@
1
- # Changelog
2
-
3
- ## [integrations/sqlalchemy-v0.1.0] - 2026-04-02
4
-
5
- ### 🚀 Features
6
-
7
- - Initial release of `sqlalchemy-haystack` integration (#3077)
@@ -1,106 +0,0 @@
1
- Metadata-Version: 2.4
2
- Name: sqlalchemy-haystack
3
- Version: 0.1.0
4
- Summary: A SQLAlchemy integration for the Haystack framework.
5
- Project-URL: Documentation, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/sqlalchemy#readme
6
- Project-URL: Issues, https://github.com/deepset-ai/haystack-core-integrations/issues
7
- Project-URL: Source, https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/sqlalchemy
8
- Author-email: deepset GmbH <info@deepset.ai>
9
- License-Expression: Apache-2.0
10
- License-File: LICENSE.txt
11
- Classifier: Development Status :: 4 - Beta
12
- Classifier: License :: OSI Approved :: Apache Software License
13
- Classifier: Programming Language :: Python
14
- Classifier: Programming Language :: Python :: 3.10
15
- Classifier: Programming Language :: Python :: 3.11
16
- Classifier: Programming Language :: Python :: 3.12
17
- Classifier: Programming Language :: Python :: 3.13
18
- Classifier: Programming Language :: Python :: 3.14
19
- Classifier: Programming Language :: Python :: Implementation :: CPython
20
- Classifier: Programming Language :: Python :: Implementation :: PyPy
21
- Requires-Python: >=3.10
22
- Requires-Dist: haystack-ai>=2.22.0
23
- Requires-Dist: pandas>=2.2.3; python_version < '3.11'
24
- Requires-Dist: pandas>=3.0.0; python_version >= '3.11'
25
- Requires-Dist: sqlalchemy>=2.0.36
26
- Description-Content-Type: text/markdown
27
-
28
- # sqlalchemy-haystack
29
-
30
- [![PyPI - Version](https://img.shields.io/pypi/v/sqlalchemy-haystack.svg)](https://pypi.org/project/sqlalchemy-haystack)
31
- [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlalchemy-haystack.svg)](https://pypi.org/project/sqlalchemy-haystack)
32
-
33
- - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/sqlalchemy/CHANGELOG.md)
34
-
35
- ---
36
-
37
- A Haystack integration for querying SQL databases via [SQLAlchemy](https://www.sqlalchemy.org/).
38
- Provides a `SQLAlchemyTableRetriever` component that connects to any SQLAlchemy-supported database,
39
- executes a SQL query, and returns results as a Pandas DataFrame and an optional Markdown table.
40
-
41
- ## Installation
42
-
43
- ```bash
44
- pip install sqlalchemy-haystack
45
- ```
46
-
47
- You also need to install the appropriate database driver for your backend:
48
-
49
- | Backend | Driver package |
50
- |---------|---------------|
51
- | PostgreSQL | `psycopg2-binary` or `psycopg[binary]` |
52
- | MySQL / MariaDB | `pymysql` or `mysqlclient` |
53
- | SQLite | built-in (no extra package needed) |
54
- | MSSQL | `pyodbc` |
55
- | Oracle | `cx_oracle` or `oracledb` |
56
-
57
- ## Usage
58
-
59
- ```python
60
- from haystack_integrations.components.retrievers.sqlalchemy import SQLAlchemyTableRetriever
61
-
62
- # SQLite in-memory example (no driver needed)
63
- retriever = SQLAlchemyTableRetriever(
64
- drivername="sqlite",
65
- database=":memory:",
66
- init_script=[
67
- "CREATE TABLE products (id INTEGER, name TEXT, price REAL)",
68
- "INSERT INTO products VALUES (1, 'Widget', 9.99)",
69
- "INSERT INTO products VALUES (2, 'Gadget', 19.99)",
70
- ],
71
- )
72
- retriever.warm_up()
73
-
74
- result = retriever.run(query="SELECT * FROM products WHERE price < 15")
75
- print(result["dataframe"])
76
- print(result["table"])
77
- ```
78
-
79
- For PostgreSQL:
80
-
81
- ```python
82
- from haystack.utils import Secret
83
-
84
- retriever = SQLAlchemyTableRetriever(
85
- drivername="postgresql+psycopg2",
86
- host="localhost",
87
- port=5432,
88
- database="mydb",
89
- username="myuser",
90
- password=Secret.from_env_var("DB_PASSWORD"),
91
- )
92
- ```
93
-
94
- ## Security
95
-
96
- This component executes raw SQL queries passed at runtime. Keep the following in mind:
97
-
98
- - **Never pass unsanitised user input** directly as a query — this exposes you to SQL injection.
99
- - **Use a read-only database user.** This is the most effective mitigation. Even if a malicious
100
- query is executed, a read-only user cannot modify or delete data.
101
- - **Restrict database permissions** to the minimum required — specific tables and schemas only,
102
- no DDL privileges (no `CREATE`, `DROP`, `ALTER`).
103
-
104
- ## Contributing
105
-
106
- Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).
@@ -1,79 +0,0 @@
1
- # sqlalchemy-haystack
2
-
3
- [![PyPI - Version](https://img.shields.io/pypi/v/sqlalchemy-haystack.svg)](https://pypi.org/project/sqlalchemy-haystack)
4
- [![PyPI - Python Version](https://img.shields.io/pypi/pyversions/sqlalchemy-haystack.svg)](https://pypi.org/project/sqlalchemy-haystack)
5
-
6
- - [Changelog](https://github.com/deepset-ai/haystack-core-integrations/blob/main/integrations/sqlalchemy/CHANGELOG.md)
7
-
8
- ---
9
-
10
- A Haystack integration for querying SQL databases via [SQLAlchemy](https://www.sqlalchemy.org/).
11
- Provides a `SQLAlchemyTableRetriever` component that connects to any SQLAlchemy-supported database,
12
- executes a SQL query, and returns results as a Pandas DataFrame and an optional Markdown table.
13
-
14
- ## Installation
15
-
16
- ```bash
17
- pip install sqlalchemy-haystack
18
- ```
19
-
20
- You also need to install the appropriate database driver for your backend:
21
-
22
- | Backend | Driver package |
23
- |---------|---------------|
24
- | PostgreSQL | `psycopg2-binary` or `psycopg[binary]` |
25
- | MySQL / MariaDB | `pymysql` or `mysqlclient` |
26
- | SQLite | built-in (no extra package needed) |
27
- | MSSQL | `pyodbc` |
28
- | Oracle | `cx_oracle` or `oracledb` |
29
-
30
- ## Usage
31
-
32
- ```python
33
- from haystack_integrations.components.retrievers.sqlalchemy import SQLAlchemyTableRetriever
34
-
35
- # SQLite in-memory example (no driver needed)
36
- retriever = SQLAlchemyTableRetriever(
37
- drivername="sqlite",
38
- database=":memory:",
39
- init_script=[
40
- "CREATE TABLE products (id INTEGER, name TEXT, price REAL)",
41
- "INSERT INTO products VALUES (1, 'Widget', 9.99)",
42
- "INSERT INTO products VALUES (2, 'Gadget', 19.99)",
43
- ],
44
- )
45
- retriever.warm_up()
46
-
47
- result = retriever.run(query="SELECT * FROM products WHERE price < 15")
48
- print(result["dataframe"])
49
- print(result["table"])
50
- ```
51
-
52
- For PostgreSQL:
53
-
54
- ```python
55
- from haystack.utils import Secret
56
-
57
- retriever = SQLAlchemyTableRetriever(
58
- drivername="postgresql+psycopg2",
59
- host="localhost",
60
- port=5432,
61
- database="mydb",
62
- username="myuser",
63
- password=Secret.from_env_var("DB_PASSWORD"),
64
- )
65
- ```
66
-
67
- ## Security
68
-
69
- This component executes raw SQL queries passed at runtime. Keep the following in mind:
70
-
71
- - **Never pass unsanitised user input** directly as a query — this exposes you to SQL injection.
72
- - **Use a read-only database user.** This is the most effective mitigation. Even if a malicious
73
- query is executed, a read-only user cannot modify or delete data.
74
- - **Restrict database permissions** to the minimum required — specific tables and schemas only,
75
- no DDL privileges (no `CREATE`, `DROP`, `ALTER`).
76
-
77
- ## Contributing
78
-
79
- Refer to the general [Contribution Guidelines](https://github.com/deepset-ai/haystack-core-integrations/blob/main/CONTRIBUTING.md).