prefect-sqlalchemy 0.6.1__tar.gz → 0.7.0__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.
Files changed (27) hide show
  1. {prefect_sqlalchemy-0.6.1/prefect_sqlalchemy.egg-info → prefect_sqlalchemy-0.7.0}/PKG-INFO +4 -4
  2. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/README.md +1 -1
  3. prefect_sqlalchemy-0.7.0/justfile +18 -0
  4. prefect_sqlalchemy-0.7.0/prefect_sqlalchemy/_version.py +24 -0
  5. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/prefect_sqlalchemy/database.py +56 -47
  6. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0/prefect_sqlalchemy.egg-info}/PKG-INFO +4 -4
  7. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/prefect_sqlalchemy.egg-info/SOURCES.txt +4 -0
  8. prefect_sqlalchemy-0.7.0/prefect_sqlalchemy.egg-info/scm_file_list.json +19 -0
  9. prefect_sqlalchemy-0.7.0/prefect_sqlalchemy.egg-info/scm_version.json +8 -0
  10. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/pyproject.toml +3 -3
  11. prefect_sqlalchemy-0.7.0/tests/test_cursor_reuse.py +120 -0
  12. prefect_sqlalchemy-0.6.1/prefect_sqlalchemy/_version.py +0 -34
  13. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/LICENSE +0 -0
  14. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/MANIFEST.in +0 -0
  15. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/prefect_sqlalchemy/__init__.py +0 -0
  16. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/prefect_sqlalchemy/credentials.py +0 -0
  17. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/prefect_sqlalchemy.egg-info/dependency_links.txt +0 -0
  18. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/prefect_sqlalchemy.egg-info/entry_points.txt +0 -0
  19. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/prefect_sqlalchemy.egg-info/requires.txt +0 -0
  20. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/prefect_sqlalchemy.egg-info/top_level.txt +0 -0
  21. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/setup.cfg +0 -0
  22. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/tests/conftest.py +0 -0
  23. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/tests/test_async_dispatch.py +0 -0
  24. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/tests/test_block_standards.py +0 -0
  25. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/tests/test_credentials.py +0 -0
  26. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/tests/test_database.py +0 -0
  27. {prefect_sqlalchemy-0.6.1 → prefect_sqlalchemy-0.7.0}/tests/test_version.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: prefect-sqlalchemy
3
- Version: 0.6.1
3
+ Version: 0.7.0
4
4
  Summary: Prefect integrations for working with databases
5
5
  Author-email: "Prefect Technologies, Inc." <help@prefect.io>
6
6
  License: Apache License 2.0
@@ -11,12 +11,12 @@ Classifier: Intended Audience :: Developers
11
11
  Classifier: Intended Audience :: System Administrators
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Programming Language :: Python :: 3 :: Only
14
- Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
17
16
  Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
18
  Classifier: Topic :: Software Development :: Libraries
19
- Requires-Python: >=3.10
19
+ Requires-Python: >=3.11
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: sqlalchemy<3,>=1.4.31
@@ -32,4 +32,4 @@ Dynamic: license-file
32
32
  <img src="https://img.shields.io/pypi/dm/prefect-sqlalchemy?color=0052FF&labelColor=090422" /></a>
33
33
  </p>
34
34
 
35
- See the docs at [https://docs.prefect.io/integrations/prefect-sqlalchemy](https://docs.prefect.io/integrations/prefect-alchemy) for more information.
35
+ See the docs at [https://www.prefect.io/docs/integrations/prefect-sqlalchemy](https://www.prefect.io/docs/integrations/prefect-sqlalchemy) for more information.
@@ -7,4 +7,4 @@
7
7
  <img src="https://img.shields.io/pypi/dm/prefect-sqlalchemy?color=0052FF&labelColor=090422" /></a>
8
8
  </p>
9
9
 
10
- See the docs at [https://docs.prefect.io/integrations/prefect-sqlalchemy](https://docs.prefect.io/integrations/prefect-alchemy) for more information.
10
+ See the docs at [https://www.prefect.io/docs/integrations/prefect-sqlalchemy](https://www.prefect.io/docs/integrations/prefect-sqlalchemy) for more information.
@@ -0,0 +1,18 @@
1
+ test:
2
+ uv run pytest
3
+
4
+ # Generate API reference documentation for prefect-sqlalchemy
5
+ api-ref:
6
+ #!/usr/bin/env bash
7
+ REPO_ROOT="$(git rev-parse --show-toplevel)"
8
+ cd "$REPO_ROOT"
9
+ uvx --with-editable ./src/integrations/prefect-sqlalchemy \
10
+ --python 3.12 \
11
+ --isolated \
12
+ 'mdxify>=0.2.45' \
13
+ --all \
14
+ --root-module prefect_sqlalchemy \
15
+ --output-dir docs/integrations/prefect-sqlalchemy/api-ref \
16
+ --anchor-name "prefect-sqlalchemy-sdk-reference" \
17
+ --repo-url https://github.com/PrefectHQ/prefect \
18
+ --include-inheritance
@@ -0,0 +1,24 @@
1
+ # file generated by vcs-versioning
2
+ # don't change, don't track in version control
3
+ from __future__ import annotations
4
+
5
+ __all__ = [
6
+ "__version__",
7
+ "__version_tuple__",
8
+ "version",
9
+ "version_tuple",
10
+ "__commit_id__",
11
+ "commit_id",
12
+ ]
13
+
14
+ version: str
15
+ __version__: str
16
+ __version_tuple__: tuple[int | str, ...]
17
+ version_tuple: tuple[int | str, ...]
18
+ commit_id: str | None
19
+ __commit_id__: str | None
20
+
21
+ __version__ = version = '0.7.0'
22
+ __version_tuple__ = version_tuple = (0, 7, 0)
23
+
24
+ __commit_id__ = commit_id = 'g257468048'
@@ -3,6 +3,7 @@
3
3
  from contextlib import AsyncExitStack, ExitStack, asynccontextmanager, contextmanager
4
4
  from typing import Annotated, Any, Dict, List, Optional, Tuple, Union
5
5
 
6
+ import cloudpickle
6
7
  from pydantic import AfterValidator, ConfigDict, Field
7
8
  from sqlalchemy import __version__ as SQLALCHEMY_VERSION
8
9
  from sqlalchemy.engine import Connection, Engine, create_engine
@@ -13,7 +14,7 @@ from sqlalchemy.sql import text
13
14
  from typing_extensions import Literal
14
15
 
15
16
  from prefect.blocks.abstract import CredentialsBlock, DatabaseBlock
16
- from prefect.utilities.hashing import hash_objects
17
+ from prefect.utilities.hashing import stable_hash
17
18
  from prefect_sqlalchemy.credentials import (
18
19
  AsyncDriver,
19
20
  ConnectionComponents,
@@ -92,8 +93,8 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
92
93
  """
93
94
 
94
95
  _block_type_name = "SQLAlchemy Connector"
95
- _logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/3c7dff04f70aaf4528e184a3b028f9e40b98d68c-250x250.png" # type: ignore
96
- _documentation_url = "https://docs.prefect.io/integrations/prefect-sqlalchemy" # type: ignore
96
+ _logo_url = "https://raw.githubusercontent.com/PrefectHQ/prefect/420d0d6a78bb6df1fc18bcf188fdad43c1d22ea9/assets/block-logos/sqlalchemy.png" # type: ignore
97
+ _documentation_url = "https://www.prefect.io/docs/integrations/prefect-sqlalchemy" # type: ignore
97
98
  model_config = ConfigDict(arbitrary_types_allowed=True)
98
99
 
99
100
  connection_info: Union[ConnectionComponents, DBUrl] = Field(
@@ -148,7 +149,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
148
149
  if self._exit_stack is None:
149
150
  self._exit_stack = ExitStack()
150
151
 
151
- def get_engine(self, **create_engine_kwargs: Dict[str, Any]) -> Engine:
152
+ def get_engine(self, **create_engine_kwargs: Any) -> Engine:
152
153
  """
153
154
  Returns an authenticated engine that can be
154
155
  used to query from databases.
@@ -198,9 +199,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
198
199
 
199
200
  return engine
200
201
 
201
- def get_connection(
202
- self, begin: bool = True, **connect_kwargs: Dict[str, Any]
203
- ) -> Connection:
202
+ def get_connection(self, begin: bool = True, **connect_kwargs: Any) -> Connection:
204
203
  """
205
204
  Returns a connection that can be used to query from databases.
206
205
 
@@ -234,7 +233,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
234
233
  def get_client(
235
234
  self,
236
235
  client_type: Literal["engine", "connection"],
237
- **get_client_kwargs: Dict[str, Any],
236
+ **get_client_kwargs: Any,
238
237
  ) -> Union[Engine, Connection]:
239
238
  """
240
239
  Returns either an engine or connection that can be used to query from databases.
@@ -276,7 +275,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
276
275
  return client
277
276
 
278
277
  @contextmanager
279
- def _manage_connection(self, **get_connection_kwargs: Dict[str, Any]):
278
+ def _manage_connection(self, **get_connection_kwargs: Any):
280
279
  """Sync context manager for managing connections."""
281
280
  with self.get_connection(**get_connection_kwargs) as connection:
282
281
  yield connection
@@ -286,7 +285,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
286
285
  connection: Connection,
287
286
  *execute_args: Tuple[Any],
288
287
  execute_commit: bool = True,
289
- **execute_kwargs: Dict[str, Any],
288
+ **execute_kwargs: Any,
290
289
  ) -> CursorResult:
291
290
  """Execute the statement synchronously."""
292
291
  result_set = connection.execute(*execute_args, **execute_kwargs)
@@ -295,29 +294,34 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
295
294
  return result_set
296
295
 
297
296
  def _get_result_set(
298
- self, *execute_args: Tuple[Any], **execute_kwargs: Dict[str, Any]
297
+ self, operation: str, *execute_args: Tuple[Any], **execute_kwargs: Any
299
298
  ) -> CursorResult:
300
299
  """
301
300
  Returns a new or existing result set.
302
301
 
303
302
  Args:
303
+ operation: The SQL query or other operation to be executed.
304
304
  *execute_args: Args to pass to execute.
305
305
  **execute_kwargs: Keyword args to pass to execute.
306
306
 
307
307
  Returns:
308
308
  The result set from the operation.
309
309
  """
310
- input_hash = hash_objects(*execute_args, **execute_kwargs)
311
- assert input_hash is not None, (
312
- "We were not able to hash your inputs, "
313
- "which resulted in an unexpected data return; "
314
- "please open an issue with a reproducible example."
310
+ # SQLAlchemy initializes shared type caches during execution, so hashing
311
+ # a TextClause can produce different keys for the same query over time.
312
+ # Keep pickle's parameter type distinctions (e.g. tuple versus list).
313
+ input_hash = stable_hash(
314
+ cloudpickle.dumps(((operation, *execute_args), execute_kwargs))
315
315
  )
316
316
 
317
317
  if input_hash not in self._unique_results.keys():
318
318
  connection = self._exit_stack.enter_context(self.get_connection())
319
319
  result_set = self._execute(
320
- connection, *execute_args, execute_commit=False, **execute_kwargs
320
+ connection,
321
+ text(operation),
322
+ *execute_args,
323
+ execute_commit=False,
324
+ **execute_kwargs,
321
325
  )
322
326
  self._unique_results[input_hash] = result_set
323
327
  else:
@@ -365,7 +369,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
365
369
  self,
366
370
  operation: str,
367
371
  parameters: Optional[Dict[str, Any]] = None,
368
- **execution_options: Dict[str, Any],
372
+ **execution_options: Any,
369
373
  ) -> Tuple[Any]:
370
374
  """
371
375
  Fetch a single result from the database.
@@ -408,7 +412,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
408
412
  ```
409
413
  """
410
414
  result_set = self._get_result_set(
411
- text(operation), parameters, execution_options=execution_options
415
+ operation, parameters, execution_options=execution_options
412
416
  )
413
417
  self.logger.debug("Preparing to fetch one row.")
414
418
  row = result_set.fetchone()
@@ -419,7 +423,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
419
423
  operation: str,
420
424
  parameters: Optional[Dict[str, Any]] = None,
421
425
  size: Optional[int] = None,
422
- **execution_options: Dict[str, Any],
426
+ **execution_options: Any,
423
427
  ) -> List[Tuple[Any]]:
424
428
  """
425
429
  Fetch a limited number of results from the database.
@@ -464,7 +468,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
464
468
  ```
465
469
  """
466
470
  result_set = self._get_result_set(
467
- text(operation), parameters, execution_options=execution_options
471
+ operation, parameters, execution_options=execution_options
468
472
  )
469
473
  size = size or self.fetch_size
470
474
  self.logger.debug(f"Preparing to fetch {size} rows.")
@@ -475,7 +479,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
475
479
  self,
476
480
  operation: str,
477
481
  parameters: Optional[Dict[str, Any]] = None,
478
- **execution_options: Dict[str, Any],
482
+ **execution_options: Any,
479
483
  ) -> List[Tuple[Any]]:
480
484
  """
481
485
  Fetch all results from the database.
@@ -518,7 +522,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
518
522
  ```
519
523
  """
520
524
  result_set = self._get_result_set(
521
- text(operation), parameters, execution_options=execution_options
525
+ operation, parameters, execution_options=execution_options
522
526
  )
523
527
  self.logger.debug("Preparing to fetch all rows.")
524
528
  rows = result_set.fetchall()
@@ -528,7 +532,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
528
532
  self,
529
533
  operation: str,
530
534
  parameters: Optional[Dict[str, Any]] = None,
531
- **execution_options: Dict[str, Any],
535
+ **execution_options: Any,
532
536
  ) -> CursorResult:
533
537
  """
534
538
  Executes an operation on the database.
@@ -572,7 +576,7 @@ class SqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
572
576
  self,
573
577
  operation: str,
574
578
  seq_of_parameters: List[Dict[str, Any]],
575
- **execution_options: Dict[str, Any],
579
+ **execution_options: Any,
576
580
  ) -> CursorResult:
577
581
  """
578
582
  Executes many operations on the database.
@@ -728,8 +732,8 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
728
732
  """
729
733
 
730
734
  _block_type_name = "Async SQLAlchemy Connector"
731
- _logo_url = "https://cdn.sanity.io/images/3ugk85nk/production/3c7dff04f70aaf4528e184a3b028f9e40b98d68c-250x250.png" # type: ignore
732
- _documentation_url = "https://docs.prefect.io/integrations/prefect-sqlalchemy" # type: ignore
735
+ _logo_url = "https://raw.githubusercontent.com/PrefectHQ/prefect/420d0d6a78bb6df1fc18bcf188fdad43c1d22ea9/assets/block-logos/sqlalchemy.png" # type: ignore
736
+ _documentation_url = "https://www.prefect.io/docs/integrations/prefect-sqlalchemy" # type: ignore
733
737
  model_config = ConfigDict(arbitrary_types_allowed=True)
734
738
 
735
739
  connection_info: Union[ConnectionComponents, DBUrl] = Field(
@@ -781,7 +785,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
781
785
  if self._exit_stack is None:
782
786
  self._exit_stack = AsyncExitStack()
783
787
 
784
- def get_engine(self, **create_engine_kwargs: Dict[str, Any]) -> AsyncEngine:
788
+ def get_engine(self, **create_engine_kwargs: Any) -> AsyncEngine:
785
789
  """
786
790
  Returns an authenticated engine that can be
787
791
  used to query from databases.
@@ -832,7 +836,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
832
836
  return engine
833
837
 
834
838
  def get_connection(
835
- self, begin: bool = True, **connect_kwargs: Dict[str, Any]
839
+ self, begin: bool = True, **connect_kwargs: Any
836
840
  ) -> AsyncConnection:
837
841
  """
838
842
  Returns a connection that can be used to query from databases.
@@ -871,7 +875,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
871
875
  def get_client(
872
876
  self,
873
877
  client_type: Literal["engine", "connection"],
874
- **get_client_kwargs: Dict[str, Any],
878
+ **get_client_kwargs: Any,
875
879
  ) -> Union[AsyncEngine, AsyncConnection]:
876
880
  """
877
881
  Returns either an engine or connection that can be used to query from databases.
@@ -913,7 +917,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
913
917
  return client
914
918
 
915
919
  @asynccontextmanager
916
- async def _manage_connection(self, **get_connection_kwargs: Dict[str, Any]):
920
+ async def _manage_connection(self, **get_connection_kwargs: Any):
917
921
  """Async context manager for managing connections."""
918
922
  async with self.get_connection(**get_connection_kwargs) as connection:
919
923
  yield connection
@@ -923,7 +927,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
923
927
  connection: AsyncConnection,
924
928
  *execute_args: Tuple[Any],
925
929
  execute_commit: bool = True,
926
- **execute_kwargs: Dict[str, Any],
930
+ **execute_kwargs: Any,
927
931
  ) -> CursorResult:
928
932
  """Execute the statement asynchronously."""
929
933
  result_set = await connection.execute(*execute_args, **execute_kwargs)
@@ -932,23 +936,24 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
932
936
  return result_set
933
937
 
934
938
  async def _get_result_set(
935
- self, *execute_args: Tuple[Any], **execute_kwargs: Dict[str, Any]
939
+ self, operation: str, *execute_args: Tuple[Any], **execute_kwargs: Any
936
940
  ) -> CursorResult:
937
941
  """
938
942
  Returns a new or existing result set.
939
943
 
940
944
  Args:
945
+ operation: The SQL query or other operation to be executed.
941
946
  *execute_args: Args to pass to execute.
942
947
  **execute_kwargs: Keyword args to pass to execute.
943
948
 
944
949
  Returns:
945
950
  The result set from the operation.
946
951
  """
947
- input_hash = hash_objects(*execute_args, **execute_kwargs)
948
- assert input_hash is not None, (
949
- "We were not able to hash your inputs, "
950
- "which resulted in an unexpected data return; "
951
- "please open an issue with a reproducible example."
952
+ # SQLAlchemy initializes shared type caches during execution, so hashing
953
+ # a TextClause can produce different keys for the same query over time.
954
+ # Keep pickle's parameter type distinctions (e.g. tuple versus list).
955
+ input_hash = stable_hash(
956
+ cloudpickle.dumps(((operation, *execute_args), execute_kwargs))
952
957
  )
953
958
 
954
959
  if input_hash not in self._unique_results.keys():
@@ -956,7 +961,11 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
956
961
  self.get_connection()
957
962
  )
958
963
  result_set = await self._execute(
959
- connection, *execute_args, execute_commit=False, **execute_kwargs
964
+ connection,
965
+ text(operation),
966
+ *execute_args,
967
+ execute_commit=False,
968
+ **execute_kwargs,
960
969
  )
961
970
  self._unique_results[input_hash] = result_set
962
971
  else:
@@ -1008,7 +1017,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
1008
1017
  self,
1009
1018
  operation: str,
1010
1019
  parameters: Optional[Dict[str, Any]] = None,
1011
- **execution_options: Dict[str, Any],
1020
+ **execution_options: Any,
1012
1021
  ) -> Tuple[Any]:
1013
1022
  """
1014
1023
  Fetch a single result from the database.
@@ -1055,7 +1064,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
1055
1064
  ```
1056
1065
  """
1057
1066
  result_set = await self._get_result_set(
1058
- text(operation), parameters, execution_options=execution_options
1067
+ operation, parameters, execution_options=execution_options
1059
1068
  )
1060
1069
  self.logger.debug("Preparing to fetch one row.")
1061
1070
  row = result_set.fetchone()
@@ -1066,7 +1075,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
1066
1075
  operation: str,
1067
1076
  parameters: Optional[Dict[str, Any]] = None,
1068
1077
  size: Optional[int] = None,
1069
- **execution_options: Dict[str, Any],
1078
+ **execution_options: Any,
1070
1079
  ) -> List[Tuple[Any]]:
1071
1080
  """
1072
1081
  Fetch a limited number of results from the database.
@@ -1115,7 +1124,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
1115
1124
  ```
1116
1125
  """
1117
1126
  result_set = await self._get_result_set(
1118
- text(operation), parameters, execution_options=execution_options
1127
+ operation, parameters, execution_options=execution_options
1119
1128
  )
1120
1129
  size = size or self.fetch_size
1121
1130
  self.logger.debug(f"Preparing to fetch {size} rows.")
@@ -1126,7 +1135,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
1126
1135
  self,
1127
1136
  operation: str,
1128
1137
  parameters: Optional[Dict[str, Any]] = None,
1129
- **execution_options: Dict[str, Any],
1138
+ **execution_options: Any,
1130
1139
  ) -> List[Tuple[Any]]:
1131
1140
  """
1132
1141
  Fetch all results from the database.
@@ -1173,7 +1182,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
1173
1182
  ```
1174
1183
  """
1175
1184
  result_set = await self._get_result_set(
1176
- text(operation), parameters, execution_options=execution_options
1185
+ operation, parameters, execution_options=execution_options
1177
1186
  )
1178
1187
  self.logger.debug("Preparing to fetch all rows.")
1179
1188
  rows = result_set.fetchall()
@@ -1183,7 +1192,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
1183
1192
  self,
1184
1193
  operation: str,
1185
1194
  parameters: Optional[Dict[str, Any]] = None,
1186
- **execution_options: Dict[str, Any],
1195
+ **execution_options: Any,
1187
1196
  ) -> CursorResult:
1188
1197
  """
1189
1198
  Executes an operation on the database.
@@ -1231,7 +1240,7 @@ class AsyncSqlAlchemyConnector(CredentialsBlock, DatabaseBlock):
1231
1240
  self,
1232
1241
  operation: str,
1233
1242
  seq_of_parameters: List[Dict[str, Any]],
1234
- **execution_options: Dict[str, Any],
1243
+ **execution_options: Any,
1235
1244
  ) -> CursorResult:
1236
1245
  """
1237
1246
  Executes many operations on the database.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: prefect-sqlalchemy
3
- Version: 0.6.1
3
+ Version: 0.7.0
4
4
  Summary: Prefect integrations for working with databases
5
5
  Author-email: "Prefect Technologies, Inc." <help@prefect.io>
6
6
  License: Apache License 2.0
@@ -11,12 +11,12 @@ Classifier: Intended Audience :: Developers
11
11
  Classifier: Intended Audience :: System Administrators
12
12
  Classifier: License :: OSI Approved :: Apache Software License
13
13
  Classifier: Programming Language :: Python :: 3 :: Only
14
- Classifier: Programming Language :: Python :: 3.10
15
14
  Classifier: Programming Language :: Python :: 3.11
16
15
  Classifier: Programming Language :: Python :: 3.12
17
16
  Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
18
  Classifier: Topic :: Software Development :: Libraries
19
- Requires-Python: >=3.10
19
+ Requires-Python: >=3.11
20
20
  Description-Content-Type: text/markdown
21
21
  License-File: LICENSE
22
22
  Requires-Dist: sqlalchemy<3,>=1.4.31
@@ -32,4 +32,4 @@ Dynamic: license-file
32
32
  <img src="https://img.shields.io/pypi/dm/prefect-sqlalchemy?color=0052FF&labelColor=090422" /></a>
33
33
  </p>
34
34
 
35
- See the docs at [https://docs.prefect.io/integrations/prefect-sqlalchemy](https://docs.prefect.io/integrations/prefect-alchemy) for more information.
35
+ See the docs at [https://www.prefect.io/docs/integrations/prefect-sqlalchemy](https://www.prefect.io/docs/integrations/prefect-sqlalchemy) for more information.
@@ -1,6 +1,7 @@
1
1
  LICENSE
2
2
  MANIFEST.in
3
3
  README.md
4
+ justfile
4
5
  pyproject.toml
5
6
  prefect_sqlalchemy/__init__.py
6
7
  prefect_sqlalchemy/_version.py
@@ -11,10 +12,13 @@ prefect_sqlalchemy.egg-info/SOURCES.txt
11
12
  prefect_sqlalchemy.egg-info/dependency_links.txt
12
13
  prefect_sqlalchemy.egg-info/entry_points.txt
13
14
  prefect_sqlalchemy.egg-info/requires.txt
15
+ prefect_sqlalchemy.egg-info/scm_file_list.json
16
+ prefect_sqlalchemy.egg-info/scm_version.json
14
17
  prefect_sqlalchemy.egg-info/top_level.txt
15
18
  tests/conftest.py
16
19
  tests/test_async_dispatch.py
17
20
  tests/test_block_standards.py
18
21
  tests/test_credentials.py
22
+ tests/test_cursor_reuse.py
19
23
  tests/test_database.py
20
24
  tests/test_version.py
@@ -0,0 +1,19 @@
1
+ {
2
+ "files": [
3
+ "LICENSE",
4
+ "MANIFEST.in",
5
+ "README.md",
6
+ "justfile",
7
+ "prefect_sqlalchemy/__init__.py",
8
+ "prefect_sqlalchemy/credentials.py",
9
+ "prefect_sqlalchemy/database.py",
10
+ "pyproject.toml",
11
+ "tests/conftest.py",
12
+ "tests/test_async_dispatch.py",
13
+ "tests/test_block_standards.py",
14
+ "tests/test_credentials.py",
15
+ "tests/test_cursor_reuse.py",
16
+ "tests/test_database.py",
17
+ "tests/test_version.py"
18
+ ]
19
+ }
@@ -0,0 +1,8 @@
1
+ {
2
+ "tag": "0.7.0",
3
+ "distance": 0,
4
+ "node": "g257468048",
5
+ "dirty": false,
6
+ "branch": "HEAD",
7
+ "node_date": "2026-11-19"
8
+ }
@@ -8,7 +8,7 @@ dependencies = ["sqlalchemy>=1.4.31,<3", "prefect>=3.6.17"]
8
8
  dynamic = ["version"]
9
9
  description = "Prefect integrations for working with databases"
10
10
  readme = "README.md"
11
- requires-python = ">=3.10"
11
+ requires-python = ">=3.11"
12
12
  license = { text = "Apache License 2.0" }
13
13
  keywords = ["prefect"]
14
14
  authors = [{ name = "Prefect Technologies, Inc.", email = "help@prefect.io" }]
@@ -18,10 +18,10 @@ classifiers = [
18
18
  "Intended Audience :: System Administrators",
19
19
  "License :: OSI Approved :: Apache Software License",
20
20
  "Programming Language :: Python :: 3 :: Only",
21
- "Programming Language :: Python :: 3.10",
22
- "Programming Language :: Python :: 3.11",
21
+ "Programming Language :: Python :: 3.11",
23
22
  "Programming Language :: Python :: 3.12",
24
23
  "Programming Language :: Python :: 3.13",
24
+ "Programming Language :: Python :: 3.14",
25
25
  "Topic :: Software Development :: Libraries",
26
26
  ]
27
27
 
@@ -0,0 +1,120 @@
1
+ import json
2
+ import subprocess
3
+ import sys
4
+ from textwrap import dedent
5
+
6
+ import pytest
7
+
8
+
9
+ @pytest.mark.parametrize("is_async", [False, True], ids=["sync", "async"])
10
+ @pytest.mark.parametrize(
11
+ "method, expected",
12
+ [
13
+ ("fetch_one", [[1], [2], None]),
14
+ ("fetch_many", [[[1]], [[2]], []]),
15
+ ("fetch_all", [[[1], [2]], [], []]),
16
+ ],
17
+ )
18
+ def test_first_parameterized_fetch_reuses_cursor(is_async, method, expected):
19
+ # A fresh process matters: previous queries can initialize SQLAlchemy's
20
+ # shared type caches and hide the first-query regression.
21
+ script = dedent(
22
+ """
23
+ import asyncio
24
+ import json
25
+ import sys
26
+
27
+ from prefect_sqlalchemy import AsyncSqlAlchemyConnector, SqlAlchemyConnector
28
+
29
+ method = sys.argv[1]
30
+ query = "SELECT :value UNION ALL SELECT :value + 1 ORDER BY 1"
31
+ kwargs = {"parameters": {"value": 1}}
32
+ if method == "fetch_many":
33
+ kwargs["size"] = 1
34
+
35
+ def normalize(result):
36
+ if method == "fetch_one":
37
+ return None if result is None else tuple(result)
38
+ return [tuple(row) for row in result]
39
+
40
+ async def run_async():
41
+ async with AsyncSqlAlchemyConnector(
42
+ connection_info="sqlite+aiosqlite:///:memory:"
43
+ ) as connector:
44
+ fetch = getattr(connector, method)
45
+ return [normalize(await fetch(query, **kwargs)) for _ in range(3)]
46
+
47
+ def run_sync():
48
+ with SqlAlchemyConnector(
49
+ connection_info="sqlite+pysqlite:///:memory:"
50
+ ) as connector:
51
+ fetch = getattr(connector, method)
52
+ return [normalize(fetch(query, **kwargs)) for _ in range(3)]
53
+
54
+ result = asyncio.run(run_async()) if sys.argv[2] == "async" else run_sync()
55
+ print(json.dumps(result))
56
+ """
57
+ )
58
+ result = subprocess.run(
59
+ [sys.executable, "-c", script, method, "async" if is_async else "sync"],
60
+ check=False,
61
+ capture_output=True,
62
+ text=True,
63
+ timeout=60,
64
+ )
65
+ assert result.returncode == 0, result.stderr
66
+ assert json.loads(result.stdout) == expected
67
+
68
+
69
+ @pytest.mark.parametrize("is_async", [False, True], ids=["sync", "async"])
70
+ def test_fetch_cache_distinguishes_adapted_parameter_types(is_async):
71
+ # SQLite adapters are process-global, so isolate them from the rest of the
72
+ # suite. Both values are valid inputs but have different database meanings.
73
+ script = dedent(
74
+ """
75
+ import asyncio
76
+ import json
77
+ import sqlite3
78
+ import sys
79
+
80
+ from prefect_sqlalchemy import AsyncSqlAlchemyConnector, SqlAlchemyConnector
81
+
82
+ sqlite3.register_adapter(tuple, lambda value: "tuple")
83
+ sqlite3.register_adapter(list, lambda value: "list")
84
+ values = [(1, 2), [1, 2]]
85
+
86
+ async def run_async():
87
+ async with AsyncSqlAlchemyConnector(
88
+ connection_info="sqlite+aiosqlite:///:memory:"
89
+ ) as connector:
90
+ return [
91
+ [tuple(row) for row in await connector.fetch_all(
92
+ "SELECT :value", parameters={"value": value}
93
+ )]
94
+ for value in values
95
+ ]
96
+
97
+ def run_sync():
98
+ with SqlAlchemyConnector(
99
+ connection_info="sqlite+pysqlite:///:memory:"
100
+ ) as connector:
101
+ return [
102
+ [tuple(row) for row in connector.fetch_all(
103
+ "SELECT :value", parameters={"value": value}
104
+ )]
105
+ for value in values
106
+ ]
107
+
108
+ result = asyncio.run(run_async()) if sys.argv[1] == "async" else run_sync()
109
+ print(json.dumps(result))
110
+ """
111
+ )
112
+ result = subprocess.run(
113
+ [sys.executable, "-c", script, "async" if is_async else "sync"],
114
+ check=False,
115
+ capture_output=True,
116
+ text=True,
117
+ timeout=60,
118
+ )
119
+ assert result.returncode == 0, result.stderr
120
+ assert json.loads(result.stdout) == [[["tuple"]], [["list"]]]
@@ -1,34 +0,0 @@
1
- # file generated by setuptools-scm
2
- # don't change, don't track in version control
3
-
4
- __all__ = [
5
- "__version__",
6
- "__version_tuple__",
7
- "version",
8
- "version_tuple",
9
- "__commit_id__",
10
- "commit_id",
11
- ]
12
-
13
- TYPE_CHECKING = False
14
- if TYPE_CHECKING:
15
- from typing import Tuple
16
- from typing import Union
17
-
18
- VERSION_TUPLE = Tuple[Union[int, str], ...]
19
- COMMIT_ID = Union[str, None]
20
- else:
21
- VERSION_TUPLE = object
22
- COMMIT_ID = object
23
-
24
- version: str
25
- __version__: str
26
- __version_tuple__: VERSION_TUPLE
27
- version_tuple: VERSION_TUPLE
28
- commit_id: COMMIT_ID
29
- __commit_id__: COMMIT_ID
30
-
31
- __version__ = version = '0.6.1'
32
- __version_tuple__ = version_tuple = (0, 6, 1)
33
-
34
- __commit_id__ = commit_id = 'gee531648b'