SQLAlchemy 2.0.47__cp313-cp313t-win_amd64.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.
Files changed (274) hide show
  1. sqlalchemy/__init__.py +283 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +184 -0
  4. sqlalchemy/connectors/asyncio.py +429 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/cyextension/__init__.py +6 -0
  7. sqlalchemy/cyextension/collections.cp313t-win_amd64.pyd +0 -0
  8. sqlalchemy/cyextension/collections.pyx +409 -0
  9. sqlalchemy/cyextension/immutabledict.cp313t-win_amd64.pyd +0 -0
  10. sqlalchemy/cyextension/immutabledict.pxd +8 -0
  11. sqlalchemy/cyextension/immutabledict.pyx +133 -0
  12. sqlalchemy/cyextension/processors.cp313t-win_amd64.pyd +0 -0
  13. sqlalchemy/cyextension/processors.pyx +68 -0
  14. sqlalchemy/cyextension/resultproxy.cp313t-win_amd64.pyd +0 -0
  15. sqlalchemy/cyextension/resultproxy.pyx +102 -0
  16. sqlalchemy/cyextension/util.cp313t-win_amd64.pyd +0 -0
  17. sqlalchemy/cyextension/util.pyx +90 -0
  18. sqlalchemy/dialects/__init__.py +62 -0
  19. sqlalchemy/dialects/_typing.py +30 -0
  20. sqlalchemy/dialects/mssql/__init__.py +88 -0
  21. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  22. sqlalchemy/dialects/mssql/base.py +4093 -0
  23. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  24. sqlalchemy/dialects/mssql/json.py +129 -0
  25. sqlalchemy/dialects/mssql/provision.py +185 -0
  26. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  27. sqlalchemy/dialects/mssql/pyodbc.py +760 -0
  28. sqlalchemy/dialects/mysql/__init__.py +104 -0
  29. sqlalchemy/dialects/mysql/aiomysql.py +250 -0
  30. sqlalchemy/dialects/mysql/asyncmy.py +231 -0
  31. sqlalchemy/dialects/mysql/base.py +3949 -0
  32. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  33. sqlalchemy/dialects/mysql/dml.py +225 -0
  34. sqlalchemy/dialects/mysql/enumerated.py +282 -0
  35. sqlalchemy/dialects/mysql/expression.py +146 -0
  36. sqlalchemy/dialects/mysql/json.py +91 -0
  37. sqlalchemy/dialects/mysql/mariadb.py +72 -0
  38. sqlalchemy/dialects/mysql/mariadbconnector.py +322 -0
  39. sqlalchemy/dialects/mysql/mysqlconnector.py +302 -0
  40. sqlalchemy/dialects/mysql/mysqldb.py +314 -0
  41. sqlalchemy/dialects/mysql/provision.py +153 -0
  42. sqlalchemy/dialects/mysql/pymysql.py +158 -0
  43. sqlalchemy/dialects/mysql/pyodbc.py +157 -0
  44. sqlalchemy/dialects/mysql/reflection.py +727 -0
  45. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  46. sqlalchemy/dialects/mysql/types.py +835 -0
  47. sqlalchemy/dialects/oracle/__init__.py +81 -0
  48. sqlalchemy/dialects/oracle/base.py +3802 -0
  49. sqlalchemy/dialects/oracle/cx_oracle.py +1555 -0
  50. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  51. sqlalchemy/dialects/oracle/oracledb.py +941 -0
  52. sqlalchemy/dialects/oracle/provision.py +297 -0
  53. sqlalchemy/dialects/oracle/types.py +316 -0
  54. sqlalchemy/dialects/oracle/vector.py +365 -0
  55. sqlalchemy/dialects/postgresql/__init__.py +167 -0
  56. sqlalchemy/dialects/postgresql/_psycopg_common.py +189 -0
  57. sqlalchemy/dialects/postgresql/array.py +519 -0
  58. sqlalchemy/dialects/postgresql/asyncpg.py +1284 -0
  59. sqlalchemy/dialects/postgresql/base.py +5378 -0
  60. sqlalchemy/dialects/postgresql/dml.py +339 -0
  61. sqlalchemy/dialects/postgresql/ext.py +540 -0
  62. sqlalchemy/dialects/postgresql/hstore.py +406 -0
  63. sqlalchemy/dialects/postgresql/json.py +404 -0
  64. sqlalchemy/dialects/postgresql/named_types.py +524 -0
  65. sqlalchemy/dialects/postgresql/operators.py +129 -0
  66. sqlalchemy/dialects/postgresql/pg8000.py +669 -0
  67. sqlalchemy/dialects/postgresql/pg_catalog.py +326 -0
  68. sqlalchemy/dialects/postgresql/provision.py +183 -0
  69. sqlalchemy/dialects/postgresql/psycopg.py +862 -0
  70. sqlalchemy/dialects/postgresql/psycopg2.py +892 -0
  71. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  72. sqlalchemy/dialects/postgresql/ranges.py +1031 -0
  73. sqlalchemy/dialects/postgresql/types.py +313 -0
  74. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  75. sqlalchemy/dialects/sqlite/aiosqlite.py +482 -0
  76. sqlalchemy/dialects/sqlite/base.py +3056 -0
  77. sqlalchemy/dialects/sqlite/dml.py +263 -0
  78. sqlalchemy/dialects/sqlite/json.py +92 -0
  79. sqlalchemy/dialects/sqlite/provision.py +229 -0
  80. sqlalchemy/dialects/sqlite/pysqlcipher.py +157 -0
  81. sqlalchemy/dialects/sqlite/pysqlite.py +756 -0
  82. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  83. sqlalchemy/engine/__init__.py +62 -0
  84. sqlalchemy/engine/_py_processors.py +136 -0
  85. sqlalchemy/engine/_py_row.py +128 -0
  86. sqlalchemy/engine/_py_util.py +74 -0
  87. sqlalchemy/engine/base.py +3390 -0
  88. sqlalchemy/engine/characteristics.py +155 -0
  89. sqlalchemy/engine/create.py +893 -0
  90. sqlalchemy/engine/cursor.py +2298 -0
  91. sqlalchemy/engine/default.py +2394 -0
  92. sqlalchemy/engine/events.py +965 -0
  93. sqlalchemy/engine/interfaces.py +3471 -0
  94. sqlalchemy/engine/mock.py +134 -0
  95. sqlalchemy/engine/processors.py +61 -0
  96. sqlalchemy/engine/reflection.py +2102 -0
  97. sqlalchemy/engine/result.py +2399 -0
  98. sqlalchemy/engine/row.py +400 -0
  99. sqlalchemy/engine/strategies.py +16 -0
  100. sqlalchemy/engine/url.py +924 -0
  101. sqlalchemy/engine/util.py +167 -0
  102. sqlalchemy/event/__init__.py +26 -0
  103. sqlalchemy/event/api.py +220 -0
  104. sqlalchemy/event/attr.py +676 -0
  105. sqlalchemy/event/base.py +472 -0
  106. sqlalchemy/event/legacy.py +258 -0
  107. sqlalchemy/event/registry.py +390 -0
  108. sqlalchemy/events.py +17 -0
  109. sqlalchemy/exc.py +832 -0
  110. sqlalchemy/ext/__init__.py +11 -0
  111. sqlalchemy/ext/associationproxy.py +2027 -0
  112. sqlalchemy/ext/asyncio/__init__.py +25 -0
  113. sqlalchemy/ext/asyncio/base.py +281 -0
  114. sqlalchemy/ext/asyncio/engine.py +1471 -0
  115. sqlalchemy/ext/asyncio/exc.py +21 -0
  116. sqlalchemy/ext/asyncio/result.py +965 -0
  117. sqlalchemy/ext/asyncio/scoping.py +1599 -0
  118. sqlalchemy/ext/asyncio/session.py +1947 -0
  119. sqlalchemy/ext/automap.py +1701 -0
  120. sqlalchemy/ext/baked.py +570 -0
  121. sqlalchemy/ext/compiler.py +600 -0
  122. sqlalchemy/ext/declarative/__init__.py +65 -0
  123. sqlalchemy/ext/declarative/extensions.py +564 -0
  124. sqlalchemy/ext/horizontal_shard.py +478 -0
  125. sqlalchemy/ext/hybrid.py +1535 -0
  126. sqlalchemy/ext/indexable.py +364 -0
  127. sqlalchemy/ext/instrumentation.py +450 -0
  128. sqlalchemy/ext/mutable.py +1085 -0
  129. sqlalchemy/ext/mypy/__init__.py +6 -0
  130. sqlalchemy/ext/mypy/apply.py +324 -0
  131. sqlalchemy/ext/mypy/decl_class.py +515 -0
  132. sqlalchemy/ext/mypy/infer.py +590 -0
  133. sqlalchemy/ext/mypy/names.py +335 -0
  134. sqlalchemy/ext/mypy/plugin.py +303 -0
  135. sqlalchemy/ext/mypy/util.py +357 -0
  136. sqlalchemy/ext/orderinglist.py +439 -0
  137. sqlalchemy/ext/serializer.py +185 -0
  138. sqlalchemy/future/__init__.py +16 -0
  139. sqlalchemy/future/engine.py +15 -0
  140. sqlalchemy/inspection.py +174 -0
  141. sqlalchemy/log.py +288 -0
  142. sqlalchemy/orm/__init__.py +171 -0
  143. sqlalchemy/orm/_orm_constructors.py +2661 -0
  144. sqlalchemy/orm/_typing.py +179 -0
  145. sqlalchemy/orm/attributes.py +2845 -0
  146. sqlalchemy/orm/base.py +971 -0
  147. sqlalchemy/orm/bulk_persistence.py +2135 -0
  148. sqlalchemy/orm/clsregistry.py +571 -0
  149. sqlalchemy/orm/collections.py +1627 -0
  150. sqlalchemy/orm/context.py +3334 -0
  151. sqlalchemy/orm/decl_api.py +2004 -0
  152. sqlalchemy/orm/decl_base.py +2192 -0
  153. sqlalchemy/orm/dependency.py +1302 -0
  154. sqlalchemy/orm/descriptor_props.py +1092 -0
  155. sqlalchemy/orm/dynamic.py +300 -0
  156. sqlalchemy/orm/evaluator.py +379 -0
  157. sqlalchemy/orm/events.py +3252 -0
  158. sqlalchemy/orm/exc.py +237 -0
  159. sqlalchemy/orm/identity.py +302 -0
  160. sqlalchemy/orm/instrumentation.py +754 -0
  161. sqlalchemy/orm/interfaces.py +1496 -0
  162. sqlalchemy/orm/loading.py +1686 -0
  163. sqlalchemy/orm/mapped_collection.py +557 -0
  164. sqlalchemy/orm/mapper.py +4444 -0
  165. sqlalchemy/orm/path_registry.py +809 -0
  166. sqlalchemy/orm/persistence.py +1788 -0
  167. sqlalchemy/orm/properties.py +935 -0
  168. sqlalchemy/orm/query.py +3459 -0
  169. sqlalchemy/orm/relationships.py +3508 -0
  170. sqlalchemy/orm/scoping.py +2148 -0
  171. sqlalchemy/orm/session.py +5280 -0
  172. sqlalchemy/orm/state.py +1168 -0
  173. sqlalchemy/orm/state_changes.py +196 -0
  174. sqlalchemy/orm/strategies.py +3470 -0
  175. sqlalchemy/orm/strategy_options.py +2568 -0
  176. sqlalchemy/orm/sync.py +164 -0
  177. sqlalchemy/orm/unitofwork.py +796 -0
  178. sqlalchemy/orm/util.py +2403 -0
  179. sqlalchemy/orm/writeonly.py +674 -0
  180. sqlalchemy/pool/__init__.py +44 -0
  181. sqlalchemy/pool/base.py +1524 -0
  182. sqlalchemy/pool/events.py +375 -0
  183. sqlalchemy/pool/impl.py +588 -0
  184. sqlalchemy/py.typed +0 -0
  185. sqlalchemy/schema.py +69 -0
  186. sqlalchemy/sql/__init__.py +145 -0
  187. sqlalchemy/sql/_dml_constructors.py +132 -0
  188. sqlalchemy/sql/_elements_constructors.py +1872 -0
  189. sqlalchemy/sql/_orm_types.py +20 -0
  190. sqlalchemy/sql/_py_util.py +75 -0
  191. sqlalchemy/sql/_selectable_constructors.py +763 -0
  192. sqlalchemy/sql/_typing.py +482 -0
  193. sqlalchemy/sql/annotation.py +587 -0
  194. sqlalchemy/sql/base.py +2293 -0
  195. sqlalchemy/sql/cache_key.py +1057 -0
  196. sqlalchemy/sql/coercions.py +1404 -0
  197. sqlalchemy/sql/compiler.py +8081 -0
  198. sqlalchemy/sql/crud.py +1752 -0
  199. sqlalchemy/sql/ddl.py +1444 -0
  200. sqlalchemy/sql/default_comparator.py +551 -0
  201. sqlalchemy/sql/dml.py +1850 -0
  202. sqlalchemy/sql/elements.py +5589 -0
  203. sqlalchemy/sql/events.py +458 -0
  204. sqlalchemy/sql/expression.py +159 -0
  205. sqlalchemy/sql/functions.py +2158 -0
  206. sqlalchemy/sql/lambdas.py +1442 -0
  207. sqlalchemy/sql/naming.py +209 -0
  208. sqlalchemy/sql/operators.py +2623 -0
  209. sqlalchemy/sql/roles.py +323 -0
  210. sqlalchemy/sql/schema.py +6222 -0
  211. sqlalchemy/sql/selectable.py +7265 -0
  212. sqlalchemy/sql/sqltypes.py +3930 -0
  213. sqlalchemy/sql/traversals.py +1024 -0
  214. sqlalchemy/sql/type_api.py +2368 -0
  215. sqlalchemy/sql/util.py +1485 -0
  216. sqlalchemy/sql/visitors.py +1164 -0
  217. sqlalchemy/testing/__init__.py +96 -0
  218. sqlalchemy/testing/assertions.py +994 -0
  219. sqlalchemy/testing/assertsql.py +520 -0
  220. sqlalchemy/testing/asyncio.py +135 -0
  221. sqlalchemy/testing/config.py +434 -0
  222. sqlalchemy/testing/engines.py +483 -0
  223. sqlalchemy/testing/entities.py +117 -0
  224. sqlalchemy/testing/exclusions.py +476 -0
  225. sqlalchemy/testing/fixtures/__init__.py +28 -0
  226. sqlalchemy/testing/fixtures/base.py +384 -0
  227. sqlalchemy/testing/fixtures/mypy.py +332 -0
  228. sqlalchemy/testing/fixtures/orm.py +227 -0
  229. sqlalchemy/testing/fixtures/sql.py +482 -0
  230. sqlalchemy/testing/pickleable.py +155 -0
  231. sqlalchemy/testing/plugin/__init__.py +6 -0
  232. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  233. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  234. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  235. sqlalchemy/testing/profiling.py +329 -0
  236. sqlalchemy/testing/provision.py +603 -0
  237. sqlalchemy/testing/requirements.py +1945 -0
  238. sqlalchemy/testing/schema.py +198 -0
  239. sqlalchemy/testing/suite/__init__.py +19 -0
  240. sqlalchemy/testing/suite/test_cte.py +237 -0
  241. sqlalchemy/testing/suite/test_ddl.py +389 -0
  242. sqlalchemy/testing/suite/test_deprecations.py +153 -0
  243. sqlalchemy/testing/suite/test_dialect.py +776 -0
  244. sqlalchemy/testing/suite/test_insert.py +630 -0
  245. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  246. sqlalchemy/testing/suite/test_results.py +504 -0
  247. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  248. sqlalchemy/testing/suite/test_select.py +2010 -0
  249. sqlalchemy/testing/suite/test_sequence.py +317 -0
  250. sqlalchemy/testing/suite/test_types.py +2147 -0
  251. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  252. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  253. sqlalchemy/testing/util.py +535 -0
  254. sqlalchemy/testing/warnings.py +52 -0
  255. sqlalchemy/types.py +74 -0
  256. sqlalchemy/util/__init__.py +162 -0
  257. sqlalchemy/util/_collections.py +712 -0
  258. sqlalchemy/util/_concurrency_py3k.py +288 -0
  259. sqlalchemy/util/_has_cy.py +40 -0
  260. sqlalchemy/util/_py_collections.py +541 -0
  261. sqlalchemy/util/compat.py +421 -0
  262. sqlalchemy/util/concurrency.py +110 -0
  263. sqlalchemy/util/deprecations.py +401 -0
  264. sqlalchemy/util/langhelpers.py +2203 -0
  265. sqlalchemy/util/preloaded.py +150 -0
  266. sqlalchemy/util/queue.py +322 -0
  267. sqlalchemy/util/tool_support.py +201 -0
  268. sqlalchemy/util/topological.py +120 -0
  269. sqlalchemy/util/typing.py +734 -0
  270. sqlalchemy-2.0.47.dist-info/METADATA +243 -0
  271. sqlalchemy-2.0.47.dist-info/RECORD +274 -0
  272. sqlalchemy-2.0.47.dist-info/WHEEL +5 -0
  273. sqlalchemy-2.0.47.dist-info/licenses/LICENSE +19 -0
  274. sqlalchemy-2.0.47.dist-info/top_level.txt +1 -0
@@ -0,0 +1,893 @@
1
+ # engine/create.py
2
+ # Copyright (C) 2005-2026 the SQLAlchemy authors and contributors
3
+ # <see AUTHORS file>
4
+ #
5
+ # This module is part of SQLAlchemy and is released under
6
+ # the MIT License: https://www.opensource.org/licenses/mit-license.php
7
+
8
+ from __future__ import annotations
9
+
10
+ import inspect
11
+ import typing
12
+ from typing import Any
13
+ from typing import Callable
14
+ from typing import cast
15
+ from typing import Dict
16
+ from typing import List
17
+ from typing import Optional
18
+ from typing import overload
19
+ from typing import Type
20
+ from typing import Union
21
+
22
+ from . import base
23
+ from . import url as _url
24
+ from .interfaces import DBAPIConnection
25
+ from .mock import create_mock_engine
26
+ from .. import event
27
+ from .. import exc
28
+ from .. import util
29
+ from ..pool import _AdhocProxiedConnection
30
+ from ..pool import ConnectionPoolEntry
31
+ from ..sql import compiler
32
+ from ..util import immutabledict
33
+
34
+ if typing.TYPE_CHECKING:
35
+ from .base import Engine
36
+ from .interfaces import _ExecuteOptions
37
+ from .interfaces import _ParamStyle
38
+ from .interfaces import IsolationLevel
39
+ from .url import URL
40
+ from ..log import _EchoFlagType
41
+ from ..pool import _CreatorFnType
42
+ from ..pool import _CreatorWRecFnType
43
+ from ..pool import _ResetStyleArgType
44
+ from ..pool import Pool
45
+ from ..util.typing import Literal
46
+
47
+
48
+ @overload
49
+ def create_engine(
50
+ url: Union[str, URL],
51
+ *,
52
+ connect_args: Dict[Any, Any] = ...,
53
+ convert_unicode: bool = ...,
54
+ creator: Union[_CreatorFnType, _CreatorWRecFnType] = ...,
55
+ echo: _EchoFlagType = ...,
56
+ echo_pool: _EchoFlagType = ...,
57
+ enable_from_linting: bool = ...,
58
+ execution_options: _ExecuteOptions = ...,
59
+ future: Literal[True],
60
+ hide_parameters: bool = ...,
61
+ implicit_returning: Literal[True] = ...,
62
+ insertmanyvalues_page_size: int = ...,
63
+ isolation_level: IsolationLevel = ...,
64
+ json_deserializer: Callable[..., Any] = ...,
65
+ json_serializer: Callable[..., Any] = ...,
66
+ label_length: Optional[int] = ...,
67
+ logging_name: str = ...,
68
+ max_identifier_length: Optional[int] = ...,
69
+ max_overflow: int = ...,
70
+ module: Optional[Any] = ...,
71
+ paramstyle: Optional[_ParamStyle] = ...,
72
+ pool: Optional[Pool] = ...,
73
+ poolclass: Optional[Type[Pool]] = ...,
74
+ pool_logging_name: str = ...,
75
+ pool_pre_ping: bool = ...,
76
+ pool_size: int = ...,
77
+ pool_recycle: int = ...,
78
+ pool_reset_on_return: Optional[_ResetStyleArgType] = ...,
79
+ pool_timeout: float = ...,
80
+ pool_use_lifo: bool = ...,
81
+ plugins: List[str] = ...,
82
+ query_cache_size: int = ...,
83
+ use_insertmanyvalues: bool = ...,
84
+ **kwargs: Any,
85
+ ) -> Engine: ...
86
+
87
+
88
+ @overload
89
+ def create_engine(url: Union[str, URL], **kwargs: Any) -> Engine: ...
90
+
91
+
92
+ @util.deprecated_params(
93
+ strategy=(
94
+ "1.4",
95
+ "The :paramref:`_sa.create_engine.strategy` keyword is deprecated, "
96
+ "and the only argument accepted is 'mock'; please use "
97
+ ":func:`.create_mock_engine` going forward. For general "
98
+ "customization of create_engine which may have been accomplished "
99
+ "using strategies, see :class:`.CreateEnginePlugin`.",
100
+ ),
101
+ empty_in_strategy=(
102
+ "1.4",
103
+ "The :paramref:`_sa.create_engine.empty_in_strategy` keyword is "
104
+ "deprecated, and no longer has any effect. All IN expressions "
105
+ "are now rendered using "
106
+ 'the "expanding parameter" strategy which renders a set of bound'
107
+ 'expressions, or an "empty set" SELECT, at statement execution'
108
+ "time.",
109
+ ),
110
+ implicit_returning=(
111
+ "2.0",
112
+ "The :paramref:`_sa.create_engine.implicit_returning` parameter "
113
+ "is deprecated and will be removed in a future release. ",
114
+ ),
115
+ )
116
+ def create_engine(url: Union[str, _url.URL], **kwargs: Any) -> Engine:
117
+ """Create a new :class:`_engine.Engine` instance.
118
+
119
+ The standard calling form is to send the :ref:`URL <database_urls>` as the
120
+ first positional argument, usually a string
121
+ that indicates database dialect and connection arguments::
122
+
123
+ engine = create_engine("postgresql+psycopg2://scott:tiger@localhost/test")
124
+
125
+ .. note::
126
+
127
+ Please review :ref:`database_urls` for general guidelines in composing
128
+ URL strings. In particular, special characters, such as those often
129
+ part of passwords, must be URL encoded to be properly parsed.
130
+
131
+ Additional keyword arguments may then follow it which
132
+ establish various options on the resulting :class:`_engine.Engine`
133
+ and its underlying :class:`.Dialect` and :class:`_pool.Pool`
134
+ constructs::
135
+
136
+ engine = create_engine(
137
+ "mysql+mysqldb://scott:tiger@hostname/dbname",
138
+ pool_recycle=3600,
139
+ echo=True,
140
+ )
141
+
142
+ The string form of the URL is
143
+ ``dialect[+driver]://user:password@host/dbname[?key=value..]``, where
144
+ ``dialect`` is a database name such as ``mysql``, ``oracle``,
145
+ ``postgresql``, etc., and ``driver`` the name of a DBAPI, such as
146
+ ``psycopg2``, ``pyodbc``, ``cx_oracle``, etc. Alternatively,
147
+ the URL can be an instance of :class:`~sqlalchemy.engine.url.URL`.
148
+
149
+ ``**kwargs`` takes a wide variety of options which are routed
150
+ towards their appropriate components. Arguments may be specific to
151
+ the :class:`_engine.Engine`, the underlying :class:`.Dialect`,
152
+ as well as the
153
+ :class:`_pool.Pool`. Specific dialects also accept keyword arguments that
154
+ are unique to that dialect. Here, we describe the parameters
155
+ that are common to most :func:`_sa.create_engine()` usage.
156
+
157
+ Once established, the newly resulting :class:`_engine.Engine` will
158
+ request a connection from the underlying :class:`_pool.Pool` once
159
+ :meth:`_engine.Engine.connect` is called, or a method which depends on it
160
+ such as :meth:`_engine.Engine.execute` is invoked. The
161
+ :class:`_pool.Pool` in turn
162
+ will establish the first actual DBAPI connection when this request
163
+ is received. The :func:`_sa.create_engine` call itself does **not**
164
+ establish any actual DBAPI connections directly.
165
+
166
+ .. seealso::
167
+
168
+ :doc:`/core/engines`
169
+
170
+ :doc:`/dialects/index`
171
+
172
+ :ref:`connections_toplevel`
173
+
174
+ :param connect_args: a dictionary of options which will be
175
+ passed directly to the DBAPI's ``connect()`` method as
176
+ additional keyword arguments. See the example
177
+ at :ref:`custom_dbapi_args`.
178
+
179
+ :param creator: a callable which returns a DBAPI connection.
180
+ This creation function will be passed to the underlying
181
+ connection pool and will be used to create all new database
182
+ connections. Usage of this function causes connection
183
+ parameters specified in the URL argument to be bypassed.
184
+
185
+ This hook is not as flexible as the newer
186
+ :meth:`_events.DialectEvents.do_connect` hook which allows complete
187
+ control over how a connection is made to the database, given the full
188
+ set of URL arguments and state beforehand.
189
+
190
+ .. seealso::
191
+
192
+ :meth:`_events.DialectEvents.do_connect` - event hook that allows
193
+ full control over DBAPI connection mechanics.
194
+
195
+ :ref:`custom_dbapi_args`
196
+
197
+ :param echo=False: if True, the Engine will log all statements
198
+ as well as a ``repr()`` of their parameter lists to the default log
199
+ handler, which defaults to ``sys.stdout`` for output. If set to the
200
+ string ``"debug"``, result rows will be printed to the standard output
201
+ as well. The ``echo`` attribute of ``Engine`` can be modified at any
202
+ time to turn logging on and off; direct control of logging is also
203
+ available using the standard Python ``logging`` module.
204
+
205
+ .. seealso::
206
+
207
+ :ref:`dbengine_logging` - further detail on how to configure
208
+ logging.
209
+
210
+
211
+ :param echo_pool=False: if True, the connection pool will log
212
+ informational output such as when connections are invalidated
213
+ as well as when connections are recycled to the default log handler,
214
+ which defaults to ``sys.stdout`` for output. If set to the string
215
+ ``"debug"``, the logging will include pool checkouts and checkins.
216
+ Direct control of logging is also available using the standard Python
217
+ ``logging`` module.
218
+
219
+ .. seealso::
220
+
221
+ :ref:`dbengine_logging` - further detail on how to configure
222
+ logging.
223
+
224
+
225
+ :param empty_in_strategy: No longer used; SQLAlchemy now uses
226
+ "empty set" behavior for IN in all cases.
227
+
228
+ :param enable_from_linting: defaults to True. Will emit a warning
229
+ if a given SELECT statement is found to have un-linked FROM elements
230
+ which would cause a cartesian product.
231
+
232
+ .. versionadded:: 1.4
233
+
234
+ .. seealso::
235
+
236
+ :ref:`change_4737`
237
+
238
+ :param execution_options: Dictionary execution options which will
239
+ be applied to all connections. See
240
+ :meth:`~sqlalchemy.engine.Connection.execution_options`
241
+
242
+ :param future: Use the 2.0 style :class:`_engine.Engine` and
243
+ :class:`_engine.Connection` API.
244
+
245
+ As of SQLAlchemy 2.0, this parameter is present for backwards
246
+ compatibility only and must remain at its default value of ``True``.
247
+
248
+ The :paramref:`_sa.create_engine.future` parameter will be
249
+ deprecated in a subsequent 2.x release and eventually removed.
250
+
251
+ .. versionadded:: 1.4
252
+
253
+ .. versionchanged:: 2.0 All :class:`_engine.Engine` objects are
254
+ "future" style engines and there is no longer a ``future=False``
255
+ mode of operation.
256
+
257
+ .. seealso::
258
+
259
+ :ref:`migration_20_toplevel`
260
+
261
+ :param hide_parameters: Boolean, when set to True, SQL statement parameters
262
+ will not be displayed in INFO logging nor will they be formatted into
263
+ the string representation of :class:`.StatementError` objects.
264
+
265
+ .. versionadded:: 1.3.8
266
+
267
+ .. seealso::
268
+
269
+ :ref:`dbengine_logging` - further detail on how to configure
270
+ logging.
271
+
272
+ :param implicit_returning=True: Legacy parameter that may only be set
273
+ to True. In SQLAlchemy 2.0, this parameter does nothing. In order to
274
+ disable "implicit returning" for statements invoked by the ORM,
275
+ configure this on a per-table basis using the
276
+ :paramref:`.Table.implicit_returning` parameter.
277
+
278
+
279
+ :param insertmanyvalues_page_size: number of rows to format into an
280
+ INSERT statement when the statement uses "insertmanyvalues" mode, which is
281
+ a paged form of bulk insert that is used for many backends when using
282
+ :term:`executemany` execution typically in conjunction with RETURNING.
283
+ Defaults to 1000, but may also be subject to dialect-specific limiting
284
+ factors which may override this value on a per-statement basis.
285
+
286
+ .. versionadded:: 2.0
287
+
288
+ .. seealso::
289
+
290
+ :ref:`engine_insertmanyvalues`
291
+
292
+ :ref:`engine_insertmanyvalues_page_size`
293
+
294
+ :paramref:`_engine.Connection.execution_options.insertmanyvalues_page_size`
295
+
296
+ :param isolation_level: optional string name of an isolation level
297
+ which will be set on all new connections unconditionally.
298
+ Isolation levels are typically some subset of the string names
299
+ ``"SERIALIZABLE"``, ``"REPEATABLE READ"``,
300
+ ``"READ COMMITTED"``, ``"READ UNCOMMITTED"`` and ``"AUTOCOMMIT"``
301
+ based on backend.
302
+
303
+ The :paramref:`_sa.create_engine.isolation_level` parameter is
304
+ in contrast to the
305
+ :paramref:`.Connection.execution_options.isolation_level`
306
+ execution option, which may be set on an individual
307
+ :class:`.Connection`, as well as the same parameter passed to
308
+ :meth:`.Engine.execution_options`, where it may be used to create
309
+ multiple engines with different isolation levels that share a common
310
+ connection pool and dialect.
311
+
312
+ .. versionchanged:: 2.0 The
313
+ :paramref:`_sa.create_engine.isolation_level`
314
+ parameter has been generalized to work on all dialects which support
315
+ the concept of isolation level, and is provided as a more succinct,
316
+ up front configuration switch in contrast to the execution option
317
+ which is more of an ad-hoc programmatic option.
318
+
319
+ .. seealso::
320
+
321
+ :ref:`dbapi_autocommit`
322
+
323
+ :param json_deserializer: for dialects that support the
324
+ :class:`_types.JSON`
325
+ datatype, this is a Python callable that will convert a JSON string
326
+ to a Python object. By default, the Python ``json.loads`` function is
327
+ used.
328
+
329
+ .. versionchanged:: 1.3.7 The SQLite dialect renamed this from
330
+ ``_json_deserializer``.
331
+
332
+ :param json_serializer: for dialects that support the :class:`_types.JSON`
333
+ datatype, this is a Python callable that will render a given object
334
+ as JSON. By default, the Python ``json.dumps`` function is used.
335
+
336
+ .. versionchanged:: 1.3.7 The SQLite dialect renamed this from
337
+ ``_json_serializer``.
338
+
339
+
340
+ :param label_length=None: optional integer value which limits
341
+ the size of dynamically generated column labels to that many
342
+ characters. If less than 6, labels are generated as
343
+ "_(counter)". If ``None``, the value of
344
+ ``dialect.max_identifier_length``, which may be affected via the
345
+ :paramref:`_sa.create_engine.max_identifier_length` parameter,
346
+ is used instead. The value of
347
+ :paramref:`_sa.create_engine.label_length`
348
+ may not be larger than that of
349
+ :paramref:`_sa.create_engine.max_identfier_length`.
350
+
351
+ .. seealso::
352
+
353
+ :paramref:`_sa.create_engine.max_identifier_length`
354
+
355
+ :param logging_name: String identifier which will be used within
356
+ the "name" field of logging records generated within the
357
+ "sqlalchemy.engine" logger. Defaults to a hexstring of the
358
+ object's id.
359
+
360
+ .. seealso::
361
+
362
+ :ref:`dbengine_logging` - further detail on how to configure
363
+ logging.
364
+
365
+ :paramref:`_engine.Connection.execution_options.logging_token`
366
+
367
+ :param max_identifier_length: integer; override the max_identifier_length
368
+ determined by the dialect. if ``None`` or zero, has no effect. This
369
+ is the database's configured maximum number of characters that may be
370
+ used in a SQL identifier such as a table name, column name, or label
371
+ name. All dialects determine this value automatically, however in the
372
+ case of a new database version for which this value has changed but
373
+ SQLAlchemy's dialect has not been adjusted, the value may be passed
374
+ here.
375
+
376
+ .. versionadded:: 1.3.9
377
+
378
+ .. seealso::
379
+
380
+ :paramref:`_sa.create_engine.label_length`
381
+
382
+ :param max_overflow=10: the number of connections to allow in
383
+ connection pool "overflow", that is connections that can be
384
+ opened above and beyond the pool_size setting, which defaults
385
+ to five. this is only used with :class:`~sqlalchemy.pool.QueuePool`.
386
+
387
+ :param module=None: reference to a Python module object (the module
388
+ itself, not its string name). Specifies an alternate DBAPI module to
389
+ be used by the engine's dialect. Each sub-dialect references a
390
+ specific DBAPI which will be imported before first connect. This
391
+ parameter causes the import to be bypassed, and the given module to
392
+ be used instead. Can be used for testing of DBAPIs as well as to
393
+ inject "mock" DBAPI implementations into the :class:`_engine.Engine`.
394
+
395
+ :param paramstyle=None: The `paramstyle <https://legacy.python.org/dev/peps/pep-0249/#paramstyle>`_
396
+ to use when rendering bound parameters. This style defaults to the
397
+ one recommended by the DBAPI itself, which is retrieved from the
398
+ ``.paramstyle`` attribute of the DBAPI. However, most DBAPIs accept
399
+ more than one paramstyle, and in particular it may be desirable
400
+ to change a "named" paramstyle into a "positional" one, or vice versa.
401
+ When this attribute is passed, it should be one of the values
402
+ ``"qmark"``, ``"numeric"``, ``"named"``, ``"format"`` or
403
+ ``"pyformat"``, and should correspond to a parameter style known
404
+ to be supported by the DBAPI in use.
405
+
406
+ :param pool=None: an already-constructed instance of
407
+ :class:`~sqlalchemy.pool.Pool`, such as a
408
+ :class:`~sqlalchemy.pool.QueuePool` instance. If non-None, this
409
+ pool will be used directly as the underlying connection pool
410
+ for the engine, bypassing whatever connection parameters are
411
+ present in the URL argument. For information on constructing
412
+ connection pools manually, see :ref:`pooling_toplevel`.
413
+
414
+ :param poolclass=None: a :class:`~sqlalchemy.pool.Pool`
415
+ subclass, which will be used to create a connection pool
416
+ instance using the connection parameters given in the URL. Note
417
+ this differs from ``pool`` in that you don't actually
418
+ instantiate the pool in this case, you just indicate what type
419
+ of pool to be used.
420
+
421
+ :param pool_logging_name: String identifier which will be used within
422
+ the "name" field of logging records generated within the
423
+ "sqlalchemy.pool" logger. Defaults to a hexstring of the object's
424
+ id.
425
+
426
+ .. seealso::
427
+
428
+ :ref:`dbengine_logging` - further detail on how to configure
429
+ logging.
430
+
431
+ :param pool_pre_ping: boolean, if True will enable the connection pool
432
+ "pre-ping" feature that tests connections for liveness upon
433
+ each checkout.
434
+
435
+ .. versionadded:: 1.2
436
+
437
+ .. seealso::
438
+
439
+ :ref:`pool_disconnects_pessimistic`
440
+
441
+ :param pool_size=5: the number of connections to keep open
442
+ inside the connection pool. This used with
443
+ :class:`~sqlalchemy.pool.QueuePool` as
444
+ well as :class:`~sqlalchemy.pool.SingletonThreadPool`. With
445
+ :class:`~sqlalchemy.pool.QueuePool`, a ``pool_size`` setting
446
+ of 0 indicates no limit; to disable pooling, set ``poolclass`` to
447
+ :class:`~sqlalchemy.pool.NullPool` instead.
448
+
449
+ :param pool_recycle=-1: this setting causes the pool to recycle
450
+ connections after the given number of seconds has passed. It
451
+ defaults to -1, or no timeout. For example, setting to 3600
452
+ means connections will be recycled after one hour. Note that
453
+ MySQL in particular will disconnect automatically if no
454
+ activity is detected on a connection for eight hours (although
455
+ this is configurable with the MySQLDB connection itself and the
456
+ server configuration as well).
457
+
458
+ .. seealso::
459
+
460
+ :ref:`pool_setting_recycle`
461
+
462
+ :param pool_reset_on_return='rollback': set the
463
+ :paramref:`_pool.Pool.reset_on_return` parameter of the underlying
464
+ :class:`_pool.Pool` object, which can be set to the values
465
+ ``"rollback"``, ``"commit"``, or ``None``.
466
+
467
+ .. seealso::
468
+
469
+ :ref:`pool_reset_on_return`
470
+
471
+ :ref:`dbapi_autocommit_skip_rollback` - a more modern approach
472
+ to using connections with no transactional instructions
473
+
474
+ :param pool_timeout=30: number of seconds to wait before giving
475
+ up on getting a connection from the pool. This is only used
476
+ with :class:`~sqlalchemy.pool.QueuePool`. This can be a float but is
477
+ subject to the limitations of Python time functions which may not be
478
+ reliable in the tens of milliseconds.
479
+
480
+ .. note: don't use 30.0 above, it seems to break with the :param tag
481
+
482
+ :param pool_use_lifo=False: use LIFO (last-in-first-out) when retrieving
483
+ connections from :class:`.QueuePool` instead of FIFO
484
+ (first-in-first-out). Using LIFO, a server-side timeout scheme can
485
+ reduce the number of connections used during non- peak periods of
486
+ use. When planning for server-side timeouts, ensure that a recycle or
487
+ pre-ping strategy is in use to gracefully handle stale connections.
488
+
489
+ .. versionadded:: 1.3
490
+
491
+ .. seealso::
492
+
493
+ :ref:`pool_use_lifo`
494
+
495
+ :ref:`pool_disconnects`
496
+
497
+ :param plugins: string list of plugin names to load. See
498
+ :class:`.CreateEnginePlugin` for background.
499
+
500
+ .. versionadded:: 1.2.3
501
+
502
+ :param query_cache_size: size of the cache used to cache the SQL string
503
+ form of queries. Set to zero to disable caching.
504
+
505
+ The cache is pruned of its least recently used items when its size reaches
506
+ N * 1.5. Defaults to 500, meaning the cache will always store at least
507
+ 500 SQL statements when filled, and will grow up to 750 items at which
508
+ point it is pruned back down to 500 by removing the 250 least recently
509
+ used items.
510
+
511
+ Caching is accomplished on a per-statement basis by generating a
512
+ cache key that represents the statement's structure, then generating
513
+ string SQL for the current dialect only if that key is not present
514
+ in the cache. All statements support caching, however some features
515
+ such as an INSERT with a large set of parameters will intentionally
516
+ bypass the cache. SQL logging will indicate statistics for each
517
+ statement whether or not it were pull from the cache.
518
+
519
+ .. note:: some ORM functions related to unit-of-work persistence as well
520
+ as some attribute loading strategies will make use of individual
521
+ per-mapper caches outside of the main cache.
522
+
523
+
524
+ .. seealso::
525
+
526
+ :ref:`sql_caching`
527
+
528
+ .. versionadded:: 1.4
529
+
530
+ :param skip_autocommit_rollback: When True, the dialect will
531
+ unconditionally skip all calls to the DBAPI ``connection.rollback()``
532
+ method if the DBAPI connection is confirmed to be in "autocommit" mode.
533
+ The availability of this feature is dialect specific; if not available,
534
+ a ``NotImplementedError`` is raised by the dialect when rollback occurs.
535
+
536
+ .. seealso::
537
+
538
+ :ref:`dbapi_autocommit_skip_rollback`
539
+
540
+ .. versionadded:: 2.0.43
541
+
542
+ :param use_insertmanyvalues: True by default, use the "insertmanyvalues"
543
+ execution style for INSERT..RETURNING statements by default.
544
+
545
+ .. versionadded:: 2.0
546
+
547
+ .. seealso::
548
+
549
+ :ref:`engine_insertmanyvalues`
550
+
551
+ """ # noqa
552
+
553
+ if "strategy" in kwargs:
554
+ strat = kwargs.pop("strategy")
555
+ if strat == "mock":
556
+ # this case is deprecated
557
+ return create_mock_engine(url, **kwargs) # type: ignore
558
+ else:
559
+ raise exc.ArgumentError("unknown strategy: %r" % strat)
560
+
561
+ kwargs.pop("empty_in_strategy", None)
562
+
563
+ # create url.URL object
564
+ u = _url.make_url(url)
565
+
566
+ u, plugins, kwargs = u._instantiate_plugins(kwargs)
567
+
568
+ entrypoint = u._get_entrypoint()
569
+ _is_async = kwargs.pop("_is_async", False)
570
+ if _is_async:
571
+ dialect_cls = entrypoint.get_async_dialect_cls(u)
572
+ else:
573
+ dialect_cls = entrypoint.get_dialect_cls(u)
574
+
575
+ if kwargs.pop("_coerce_config", False):
576
+
577
+ def pop_kwarg(key: str, default: Optional[Any] = None) -> Any:
578
+ value = kwargs.pop(key, default)
579
+ if key in dialect_cls.engine_config_types:
580
+ value = dialect_cls.engine_config_types[key](value)
581
+ return value
582
+
583
+ else:
584
+ pop_kwarg = kwargs.pop # type: ignore
585
+
586
+ dialect_args = {}
587
+ # consume dialect arguments from kwargs
588
+ for k in util.get_cls_kwargs(dialect_cls):
589
+ if k in kwargs:
590
+ dialect_args[k] = pop_kwarg(k)
591
+
592
+ dbapi = kwargs.pop("module", None)
593
+ if dbapi is None:
594
+ dbapi_args = {}
595
+
596
+ if "import_dbapi" in dialect_cls.__dict__:
597
+ dbapi_meth = dialect_cls.import_dbapi
598
+
599
+ elif hasattr(dialect_cls, "dbapi") and inspect.ismethod(
600
+ dialect_cls.dbapi
601
+ ):
602
+ util.warn_deprecated(
603
+ "The dbapi() classmethod on dialect classes has been "
604
+ "renamed to import_dbapi(). Implement an import_dbapi() "
605
+ f"classmethod directly on class {dialect_cls} to remove this "
606
+ "warning; the old .dbapi() classmethod may be maintained for "
607
+ "backwards compatibility.",
608
+ "2.0",
609
+ )
610
+ dbapi_meth = dialect_cls.dbapi
611
+ else:
612
+ dbapi_meth = dialect_cls.import_dbapi
613
+
614
+ for k in util.get_func_kwargs(dbapi_meth):
615
+ if k in kwargs:
616
+ dbapi_args[k] = pop_kwarg(k)
617
+ dbapi = dbapi_meth(**dbapi_args)
618
+
619
+ dialect_args["dbapi"] = dbapi
620
+
621
+ dialect_args.setdefault("compiler_linting", compiler.NO_LINTING)
622
+ enable_from_linting = kwargs.pop("enable_from_linting", True)
623
+ if enable_from_linting:
624
+ dialect_args["compiler_linting"] ^= compiler.COLLECT_CARTESIAN_PRODUCTS
625
+
626
+ for plugin in plugins:
627
+ plugin.handle_dialect_kwargs(dialect_cls, dialect_args)
628
+
629
+ # create dialect
630
+ dialect = dialect_cls(**dialect_args)
631
+
632
+ # assemble connection arguments
633
+ (cargs_tup, cparams) = dialect.create_connect_args(u)
634
+ cparams.update(pop_kwarg("connect_args", {}))
635
+
636
+ if "async_fallback" in cparams and util.asbool(cparams["async_fallback"]):
637
+ util.warn_deprecated(
638
+ "The async_fallback dialect argument is deprecated and will be "
639
+ "removed in SQLAlchemy 2.1.",
640
+ "2.0",
641
+ )
642
+
643
+ cargs = list(cargs_tup) # allow mutability
644
+
645
+ # look for existing pool or create
646
+ pool = pop_kwarg("pool", None)
647
+ if pool is None:
648
+
649
+ def connect(
650
+ connection_record: Optional[ConnectionPoolEntry] = None,
651
+ ) -> DBAPIConnection:
652
+ if dialect._has_events:
653
+ for fn in dialect.dispatch.do_connect:
654
+ connection = cast(
655
+ DBAPIConnection,
656
+ fn(dialect, connection_record, cargs, cparams),
657
+ )
658
+ if connection is not None:
659
+ return connection
660
+
661
+ return dialect.connect(*cargs, **cparams)
662
+
663
+ creator = pop_kwarg("creator", connect)
664
+
665
+ poolclass = pop_kwarg("poolclass", None)
666
+ if poolclass is None:
667
+ poolclass = dialect.get_dialect_pool_class(u)
668
+ pool_args = {"dialect": dialect}
669
+
670
+ # consume pool arguments from kwargs, translating a few of
671
+ # the arguments
672
+ for k in util.get_cls_kwargs(poolclass):
673
+ tk = _pool_translate_kwargs.get(k, k)
674
+ if tk in kwargs:
675
+ pool_args[k] = pop_kwarg(tk)
676
+
677
+ for plugin in plugins:
678
+ plugin.handle_pool_kwargs(poolclass, pool_args)
679
+
680
+ pool = poolclass(creator, **pool_args)
681
+ else:
682
+ pool._dialect = dialect
683
+
684
+ if (
685
+ hasattr(pool, "_is_asyncio")
686
+ and pool._is_asyncio is not dialect.is_async
687
+ ):
688
+ raise exc.ArgumentError(
689
+ f"Pool class {pool.__class__.__name__} cannot be "
690
+ f"used with {'non-' if not dialect.is_async else ''}"
691
+ "asyncio engine",
692
+ code="pcls",
693
+ )
694
+
695
+ # create engine.
696
+ if not pop_kwarg("future", True):
697
+ raise exc.ArgumentError(
698
+ "The 'future' parameter passed to "
699
+ "create_engine() may only be set to True."
700
+ )
701
+
702
+ engineclass = base.Engine
703
+
704
+ engine_args = {}
705
+ for k in util.get_cls_kwargs(engineclass):
706
+ if k in kwargs:
707
+ engine_args[k] = pop_kwarg(k)
708
+
709
+ # internal flags used by the test suite for instrumenting / proxying
710
+ # engines with mocks etc.
711
+ _initialize = kwargs.pop("_initialize", True)
712
+
713
+ # all kwargs should be consumed
714
+ if kwargs:
715
+ raise TypeError(
716
+ "Invalid argument(s) %s sent to create_engine(), "
717
+ "using configuration %s/%s/%s. Please check that the "
718
+ "keyword arguments are appropriate for this combination "
719
+ "of components."
720
+ % (
721
+ ",".join("'%s'" % k for k in kwargs),
722
+ dialect.__class__.__name__,
723
+ pool.__class__.__name__,
724
+ engineclass.__name__,
725
+ )
726
+ )
727
+
728
+ engine = engineclass(pool, dialect, u, **engine_args)
729
+
730
+ if _initialize:
731
+ do_on_connect = dialect.on_connect_url(u)
732
+ if do_on_connect:
733
+
734
+ def on_connect(
735
+ dbapi_connection: DBAPIConnection,
736
+ connection_record: ConnectionPoolEntry,
737
+ ) -> None:
738
+ assert do_on_connect is not None
739
+ do_on_connect(dbapi_connection)
740
+
741
+ event.listen(pool, "connect", on_connect)
742
+
743
+ builtin_on_connect = dialect._builtin_onconnect()
744
+ if builtin_on_connect:
745
+ event.listen(pool, "connect", builtin_on_connect)
746
+
747
+ def first_connect(
748
+ dbapi_connection: DBAPIConnection,
749
+ connection_record: ConnectionPoolEntry,
750
+ ) -> None:
751
+ c = base.Connection(
752
+ engine,
753
+ connection=_AdhocProxiedConnection(
754
+ dbapi_connection, connection_record
755
+ ),
756
+ _has_events=False,
757
+ # reconnecting will be a reentrant condition, so if the
758
+ # connection goes away, Connection is then closed
759
+ _allow_revalidate=False,
760
+ # dont trigger the autobegin sequence
761
+ # within the up front dialect checks
762
+ _allow_autobegin=False,
763
+ )
764
+ c._execution_options = util.EMPTY_DICT
765
+
766
+ try:
767
+ dialect.initialize(c)
768
+ finally:
769
+ # note that "invalidated" and "closed" are mutually
770
+ # exclusive in 1.4 Connection.
771
+ if not c.invalidated and not c.closed:
772
+ # transaction is rolled back otherwise, tested by
773
+ # test/dialect/postgresql/test_dialect.py
774
+ # ::MiscBackendTest::test_initial_transaction_state
775
+ dialect.do_rollback(c.connection)
776
+
777
+ # previously, the "first_connect" event was used here, which was then
778
+ # scaled back if the "on_connect" handler were present. now,
779
+ # since "on_connect" is virtually always present, just use
780
+ # "connect" event with once_unless_exception in all cases so that
781
+ # the connection event flow is consistent in all cases.
782
+ event.listen(
783
+ pool, "connect", first_connect, _once_unless_exception=True
784
+ )
785
+
786
+ dialect_cls.engine_created(engine)
787
+ if entrypoint is not dialect_cls:
788
+ entrypoint.engine_created(engine)
789
+
790
+ for plugin in plugins:
791
+ plugin.engine_created(engine)
792
+
793
+ return engine
794
+
795
+
796
+ def engine_from_config(
797
+ configuration: Dict[str, Any], prefix: str = "sqlalchemy.", **kwargs: Any
798
+ ) -> Engine:
799
+ """Create a new Engine instance using a configuration dictionary.
800
+
801
+ The dictionary is typically produced from a config file.
802
+
803
+ The keys of interest to ``engine_from_config()`` should be prefixed, e.g.
804
+ ``sqlalchemy.url``, ``sqlalchemy.echo``, etc. The 'prefix' argument
805
+ indicates the prefix to be searched for. Each matching key (after the
806
+ prefix is stripped) is treated as though it were the corresponding keyword
807
+ argument to a :func:`_sa.create_engine` call.
808
+
809
+ The only required key is (assuming the default prefix) ``sqlalchemy.url``,
810
+ which provides the :ref:`database URL <database_urls>`.
811
+
812
+ A select set of keyword arguments will be "coerced" to their
813
+ expected type based on string values. The set of arguments
814
+ is extensible per-dialect using the ``engine_config_types`` accessor.
815
+
816
+ :param configuration: A dictionary (typically produced from a config file,
817
+ but this is not a requirement). Items whose keys start with the value
818
+ of 'prefix' will have that prefix stripped, and will then be passed to
819
+ :func:`_sa.create_engine`.
820
+
821
+ :param prefix: Prefix to match and then strip from keys
822
+ in 'configuration'.
823
+
824
+ :param kwargs: Each keyword argument to ``engine_from_config()`` itself
825
+ overrides the corresponding item taken from the 'configuration'
826
+ dictionary. Keyword arguments should *not* be prefixed.
827
+
828
+ """
829
+
830
+ options = {
831
+ key[len(prefix) :]: configuration[key]
832
+ for key in configuration
833
+ if key.startswith(prefix)
834
+ }
835
+ options["_coerce_config"] = True
836
+ options.update(kwargs)
837
+ url = options.pop("url")
838
+ return create_engine(url, **options)
839
+
840
+
841
+ @overload
842
+ def create_pool_from_url(
843
+ url: Union[str, URL],
844
+ *,
845
+ poolclass: Optional[Type[Pool]] = ...,
846
+ logging_name: str = ...,
847
+ pre_ping: bool = ...,
848
+ size: int = ...,
849
+ recycle: int = ...,
850
+ reset_on_return: Optional[_ResetStyleArgType] = ...,
851
+ timeout: float = ...,
852
+ use_lifo: bool = ...,
853
+ **kwargs: Any,
854
+ ) -> Pool: ...
855
+
856
+
857
+ @overload
858
+ def create_pool_from_url(url: Union[str, URL], **kwargs: Any) -> Pool: ...
859
+
860
+
861
+ def create_pool_from_url(url: Union[str, URL], **kwargs: Any) -> Pool:
862
+ """Create a pool instance from the given url.
863
+
864
+ If ``poolclass`` is not provided the pool class used
865
+ is selected using the dialect specified in the URL.
866
+
867
+ The arguments passed to :func:`_sa.create_pool_from_url` are
868
+ identical to the pool argument passed to the :func:`_sa.create_engine`
869
+ function.
870
+
871
+ .. versionadded:: 2.0.10
872
+ """
873
+
874
+ for key in _pool_translate_kwargs:
875
+ if key in kwargs:
876
+ kwargs[_pool_translate_kwargs[key]] = kwargs.pop(key)
877
+
878
+ engine = create_engine(url, **kwargs, _initialize=False)
879
+ return engine.pool
880
+
881
+
882
+ _pool_translate_kwargs = immutabledict(
883
+ {
884
+ "logging_name": "pool_logging_name",
885
+ "echo": "echo_pool",
886
+ "timeout": "pool_timeout",
887
+ "recycle": "pool_recycle",
888
+ "events": "pool_events", # deprecated
889
+ "reset_on_return": "pool_reset_on_return",
890
+ "pre_ping": "pool_pre_ping",
891
+ "use_lifo": "pool_use_lifo",
892
+ }
893
+ )