1# dialects/__init__.py
2# Copyright (C) 2005-2025 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
8from __future__ import annotations
9
10from typing import Any
11from typing import Callable
12from typing import Optional
13from typing import Type
14from typing import TYPE_CHECKING
15
16from .. import util
17
18if TYPE_CHECKING:
19 from ..engine.interfaces import Dialect
20
21__all__ = ("mssql", "mysql", "oracle", "postgresql", "sqlite")
22
23
24def _auto_fn(name: str) -> Optional[Callable[[], Type[Dialect]]]:
25 """default dialect importer.
26
27 plugs into the :class:`.PluginLoader`
28 as a first-hit system.
29
30 """
31 if "." in name:
32 dialect, driver = name.split(".")
33 else:
34 dialect = name
35 driver = "base"
36
37 try:
38 if dialect == "mariadb":
39 # it's "OK" for us to hardcode here since _auto_fn is already
40 # hardcoded. if mysql / mariadb etc were third party dialects
41 # they would just publish all the entrypoints, which would actually
42 # look much nicer.
43 module: Any = __import__(
44 "sqlalchemy.dialects.mysql.mariadb"
45 ).dialects.mysql.mariadb
46 return module.loader(driver) # type: ignore
47 else:
48 module = __import__("sqlalchemy.dialects.%s" % (dialect,)).dialects
49 module = getattr(module, dialect)
50 except ImportError:
51 return None
52
53 if hasattr(module, driver):
54 module = getattr(module, driver)
55 return lambda: module.dialect
56 else:
57 return None
58
59
60registry = util.PluginLoader("sqlalchemy.dialects", auto_fn=_auto_fn)
61
62plugins = util.PluginLoader("sqlalchemy.plugins")