sqlalchemy-haystack 0.1.0__py3-none-any.whl → 1.0.1__py3-none-any.whl

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.
@@ -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)
@@ -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,7 @@
1
+ haystack_integrations/components/retrievers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
+ haystack_integrations/components/retrievers/sqlalchemy/__init__.py,sha256=liy4ghmFWcEaO3YrOddymf2JAO6mNcFR0mEExCAsMoA,216
3
+ haystack_integrations/components/retrievers/sqlalchemy/sqlalchemy_table_retriever.py,sha256=ZXCvJIPmtWumSKe-Qsr4PrGDONWo2q_Mzi6tpeK_DfA,6905
4
+ sqlalchemy_haystack-1.0.1.dist-info/METADATA,sha256=BASysSbF5mOhKxquwCTo71UMglbKa2_EJKlSUX_CQ6E,1888
5
+ sqlalchemy_haystack-1.0.1.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
6
+ sqlalchemy_haystack-1.0.1.dist-info/licenses/LICENSE.txt,sha256=wgdPKd-oq38RN75QBLghmssq3kYvVatOsKNomySh3AY,11342
7
+ sqlalchemy_haystack-1.0.1.dist-info/RECORD,,
@@ -1,4 +1,4 @@
1
1
  Wheel-Version: 1.0
2
- Generator: hatchling 1.29.0
2
+ Generator: hatchling 1.33.0
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
@@ -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,7 +0,0 @@
1
- haystack_integrations/components/retrievers/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
2
- haystack_integrations/components/retrievers/sqlalchemy/__init__.py,sha256=liy4ghmFWcEaO3YrOddymf2JAO6mNcFR0mEExCAsMoA,216
3
- haystack_integrations/components/retrievers/sqlalchemy/sqlalchemy_table_retriever.py,sha256=ZKz2NkZ1XTi4ZhwoiDG0tUorviA8p6_3LYS-zOW9F2M,6590
4
- sqlalchemy_haystack-0.1.0.dist-info/METADATA,sha256=R23RzFk7rrw5Tj9Gfm-MUV27ZrsFHqvssdDeowXo0qI,3997
5
- sqlalchemy_haystack-0.1.0.dist-info/WHEEL,sha256=QccIxa26bgl1E6uMy58deGWi-0aeIkkangHcxk2kWfw,87
6
- sqlalchemy_haystack-0.1.0.dist-info/licenses/LICENSE.txt,sha256=wgdPKd-oq38RN75QBLghmssq3kYvVatOsKNomySh3AY,11342
7
- sqlalchemy_haystack-0.1.0.dist-info/RECORD,,