Create a new async engine instance. Arguments passed to :func:`_asyncio.create_async_engine` are mostly identical to those passed to the :func:`_sa.create_engine` function. The specified dialect must be an asyncio-compatible dialect such as :ref:`dialect-postgresql-asyncpg`. ..
(url: Union[str, URL], **kw: Any)
| 74 | |
| 75 | |
| 76 | def create_async_engine(url: Union[str, URL], **kw: Any) -> AsyncEngine: |
| 77 | """Create a new async engine instance. |
| 78 | |
| 79 | Arguments passed to :func:`_asyncio.create_async_engine` are mostly |
| 80 | identical to those passed to the :func:`_sa.create_engine` function. |
| 81 | The specified dialect must be an asyncio-compatible dialect |
| 82 | such as :ref:`dialect-postgresql-asyncpg`. |
| 83 | |
| 84 | .. versionadded:: 1.4 |
| 85 | |
| 86 | :param async_creator: an async callable which returns a driver-level |
| 87 | asyncio connection. If given, the function should take no arguments, |
| 88 | and return a new asyncio connection from the underlying asyncio |
| 89 | database driver; the connection will be wrapped in the appropriate |
| 90 | structures to be used with the :class:`.AsyncEngine`. Note that the |
| 91 | parameters specified in the URL are not applied here, and the creator |
| 92 | function should use its own connection parameters. |
| 93 | |
| 94 | This parameter is the asyncio equivalent of the |
| 95 | :paramref:`_sa.create_engine.creator` parameter of the |
| 96 | :func:`_sa.create_engine` function. |
| 97 | |
| 98 | .. versionadded:: 2.0.16 |
| 99 | |
| 100 | """ |
| 101 | |
| 102 | if kw.get("server_side_cursors", False): |
| 103 | raise async_exc.AsyncMethodRequired( |
| 104 | "Can't set server_side_cursors for async engine globally; " |
| 105 | "use the connection.stream() method for an async " |
| 106 | "streaming result set" |
| 107 | ) |
| 108 | kw["_is_async"] = True |
| 109 | async_creator = kw.pop("async_creator", None) |
| 110 | if async_creator: |
| 111 | if kw.get("creator", None): |
| 112 | raise ArgumentError( |
| 113 | "Can only specify one of 'async_creator' or 'creator', " |
| 114 | "not both." |
| 115 | ) |
| 116 | |
| 117 | def creator() -> Any: |
| 118 | # note that to send adapted arguments like |
| 119 | # prepared_statement_cache_size, user would use |
| 120 | # "creator" and emulate this form here |
| 121 | return sync_engine.dialect.dbapi.connect( # type: ignore |
| 122 | async_creator_fn=async_creator |
| 123 | ) |
| 124 | |
| 125 | kw["creator"] = creator |
| 126 | sync_engine = _create_engine(url, **kw) |
| 127 | return AsyncEngine(sync_engine) |
| 128 | |
| 129 | |
| 130 | def async_engine_from_config( |