singlestoredb.connect¶
- singlestoredb.connect(host: str | None = None, user: str | None = None, password: str | None = None, port: int | None = None, database: str | None = None, driver: str | None = None, pure_python: bool | None = None, local_infile: bool | None = None, charset: str | None = None, ssl_key: str | None = None, ssl_cert: str | None = None, ssl_ca: str | None = None, ssl_disabled: bool | None = None, ssl_cipher: str | None = None, ssl_verify_cert: bool | None = None, tls_sni_servername: str | None = None, ssl_verify_identity: bool | None = None, conv: Dict[int, Callable[[...], Any]] | None = None, credential_type: str | None = None, autocommit: bool | None = None, results_type: str | None = None, buffered: bool | None = None, results_format: str | None = None, program_name: str | None = None, conn_attrs: Dict[str, str] | None = None, multi_statements: bool | None = None, client_found_rows: bool | None = None, connect_timeout: int | None = None, nan_as_null: bool | None = None, inf_as_null: bool | None = None, encoding_errors: str | None = None, track_env: bool | None = None, enable_extended_data_types: bool | None = None, vector_data_format: str | None = None) Connection ¶
Return a SingleStoreDB connection.
- Parameters:
host (str, optional) – Hostname, IP address, or URL that describes the connection. The scheme or protocol defines which database connector to use. By default, the
mysql
scheme is used. To connect to the HTTP API, the scheme can be set tohttp
orhttps
. The username, password, host, and port are specified as in a standard URL. The path indicates the database name. The overall form of the URL is:scheme://user:password@host:port/db_name
. The scheme can typically be left off (unless you are using the HTTP API):user:password@host:port/db_name
.user (str, optional) – Database user name
password (str, optional) – Database user password
port (int, optional) – Database port. This defaults to 3306 for non-HTTP connections, 80 for HTTP connections, and 443 for HTTPS connections.
database (str, optional) – Database name
pure_python (bool, optional) – Use the connector in pure Python mode
local_infile (bool, optional) – Allow local file uploads
charset (str, optional) – Character set for string values
ssl_key (str, optional) – File containing SSL key
ssl_cert (str, optional) – File containing SSL certificate
ssl_ca (str, optional) – File containing SSL certificate authority
ssl_cipher (str, optional) – Sets the SSL cipher list
ssl_disabled (bool, optional) – Disable SSL usage
ssl_verify_cert (bool, optional) – Verify the server’s certificate. This is automatically enabled if
ssl_ca
is also specified.ssl_verify_identity (bool, optional) – Verify the server’s identity
conv (dict[int, Callable], optional) – Dictionary of data conversion functions
credential_type (str, optional) – Type of authentication to use: auth.PASSWORD, auth.JWT, or auth.BROWSER_SSO
autocommit (bool, optional) – Enable autocommits
results_type (str, optional) – The form of the query results: tuples, namedtuples, dicts, numpy, polars, pandas, arrow
buffered (bool, optional) – Should the entire query result be buffered in memory? This is the default behavior which allows full cursor control of the result, but does consume more memory.
results_format (str, optional) – Deprecated. This option has been renamed to results_type.
program_name (str, optional) – Name of the program
conn_attrs (dict, optional) – Additional connection attributes for telemetry. Example: {‘program_version’: “1.0.2”, “_connector_name”: “dbt connector”}
multi_statements (bool, optional) – Should multiple statements be allowed within a single query?
connect_timeout (int, optional) – The timeout for connecting to the database in seconds. (default: 10, min: 1, max: 31536000)
nan_as_null (bool, optional) – Should NaN values be treated as NULLs when used in parameter substitutions including uploaded data?
inf_as_null (bool, optional) – Should Inf values be treated as NULLs when used in parameter substitutions including uploaded data?
encoding_errors (str, optional) – The error handler name for value decoding errors
track_env (bool, optional) – Should the connection track the SINGLESTOREDB_URL environment variable?
enable_extended_data_types (bool, optional) – Should extended data types (BSON, vector) be enabled?
vector_data_format (str, optional) – Format for vector types: json or binary
Examples
Standard database connection
>>> conn = s2.connect('me:p455w0rd@s2-host.com/my_db')
Connect to HTTP API on port 8080
>>> conn = s2.connect('http://me:p455w0rd@s2-host.com:8080/my_db')
Using an environment variable for connection string
>>> os.environ['SINGLESTOREDB_URL'] = 'me:p455w0rd@s2-host.com/my_db' >>> conn = s2.connect()
Specifying credentials using environment variables
>>> os.environ['SINGLESTOREDB_USER'] = 'me' >>> os.environ['SINGLESTOREDB_PASSWORD'] = 'p455w0rd' >>> conn = s2.connect('s2-host.com/my_db')
Specifying options with keyword parameters
>>> conn = s2.connect('s2-host.com/my_db', user='me', password='p455w0rd', local_infile=True)
Specifying options with URL parameters
>>> conn = s2.connect('s2-host.com/my_db?local_infile=True&charset=utf8')
Connecting within a context manager
>>> with s2.connect('...') as conn: ... with conn.cursor() as cur: ... cur.execute('...')
Setting session variables, the code below sets the
autocommit
option>>> conn.locals.autocommit = True
Getting session variables
>>> conn.locals.autocommit True
See also
- Return type: