create_database_engine#

safir.database.create_database_engine(url, password, *, connect_args=None, isolation_level=None, max_overflow=None, pool_pre_ping=None, pool_recycle=None, pool_size=None, pool_timeout=None)#

Create a new async database engine.

Parameters:
  • url (Union[str, Url]) – Database connection URL, not including the password.

  • password (Union[str, SecretStr, None]) – Database connection password.

  • connect_args (Optional[dict[str, Any]], default: None) – Additional connection arguments to pass directly to the underlying database driver.

  • isolation_level (Optional[str], default: None) – If specified, sets a non-default isolation level for the database engine.

  • max_overflow (Optional[int], default: None) – Maximum number of connections over the pool size for surge traffic.

  • pool_pre_ping (Optional[bool], default: None) – Check that a connection is alive before returning it to a session.

  • pool_recycle (Optional[int], default: None) – If set to an integer, discard any idle connection open for longer than the provided number of seconds rather than attempting to reuse it. If the connection idle timeout on the database server is known, setting this to slightly less than that timeout will produce the best results.

  • pool_size (Optional[int], default: None) – Connection pool size.

  • pool_timeout (Optional[float], default: None) – How long to wait for a connection from the connection pool before giving up.

Returns:

Newly-created database engine. When done with the engine, the caller must call await engine.dispose().

Return type:

sqlalchemy.ext.asyncio.AsyncEngine

Raises:

ValueError – A password was provided but the connection URL has no username.

This page was last modified on .