singlestoredb.connect(host: Optional[str] = None, user: Optional[str] = None, password: Optional[str] = None, port: Optional[int] = None, database: Optional[str] = None, driver: Optional[str] = None, pure_python: Optional[bool] = None, local_infile: Optional[bool] = None, charset: Optional[str] = None, ssl_key: Optional[str] = None, ssl_cert: Optional[str] = None, ssl_ca: Optional[str] = None, ssl_disabled: Optional[bool] = None, ssl_cipher: Optional[str] = None, ssl_verify_cert: Optional[bool] = None, ssl_verify_identity: Optional[bool] = None, conv: Optional[Dict[int, Callable[[...], Any]]] = None, credential_type: Optional[str] = None, autocommit: Optional[bool] = None, results_type: Optional[str] = None, buffered: Optional[bool] = None, results_format: Optional[str] = None) singlestoredb.connection.Connection

Return a SingleStoreDB connection.

  • 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 to http or https. 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

  • results_format (str, optional) – Deprecated. This option has been renamed to results_type.


Standard database connection

>>> conn = s2.connect('')

Connect to HTTP API on port 8080

>>> conn = s2.connect('')

Using an environment variable for connection string

>>> os.environ['SINGLESTOREDB_URL'] = ''
>>> conn = s2.connect()

Specifying credentials using environment variables

>>> os.environ['SINGLESTOREDB_USER'] = 'me'
>>> os.environ['SINGLESTOREDB_PASSWORD'] = 'p455w0rd'
>>> conn = s2.connect('')

Specifying options with keyword parameters

>>> conn = s2.connect('', user='me', password='p455w0rd',

Specifying options with URL parameters

>>> conn = s2.connect('')

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

See also


Return type