Connection Specification¶
For connecting to a database, SQLAlchemy requires to call create_engine() with an
argument specifying the detailed parameters of the connection. The parameters include:
the host and port of the database service, the username and password, and other options.
The connection may be of data type str or URL. For data
type str, the connection parameters will be parsed, and thus, special characters
must be properly escaped.
Note
For more information, see the SQLAlchemy documentation. General parameters & specific parameters for the SQLAlchemy-Exasol dialect are given in Connection Parameters.
URL¶
examples/configuration/connection_specification/0_instance_of_url.py¶
from sqlalchemy import (
URL,
create_engine,
)
url_object = URL.create(
drivername="exa+websocket",
username="sys",
password="exasol",
host="127.0.0.1",
port=8563,
# All parameters that are not keyword arguments for `URL.create` are in added
# into the `query` dictionary.
query={
"AUTOCOMMIT": "y",
"CONNECTIONLCALL": "en_US.UTF-8",
# This should NEVER be used for production systems,
# see "Disable Certificate Verification" in the User Guide.
"FINGERPRINT": "nocertcheck",
},
)
create_engine(url_object)
str¶
examples/configuration/connection_specification/1_url_string.py¶
from sqlalchemy import create_engine
username = "sys"
password = "exasol"
host = "127.0.0.1"
port = "8563"
schema = "my_schema"
# All parameters, which are not keyword arguments for `URL.create`,
# should be specified in `query` and are of the form NAME=value
# The first parameter in the query is preceded by a `?`.
# Additional parameters are preceded by a `&`.
query = (
"?AUTOCOMMIT=y"
"&CONNECTIONLCALL=en_US.UTF-8"
# This should NEVER be used for production systems,
# see "Disable Certificate Verification" in the User Guide.
"&FINGERPRINT=nocertcheck"
)
url_string = f"exa+websocket://{username}:{password}@{host}:{port}/{schema}{query}"
create_engine(url_string)