Supported Python Libraries

SingleStore supports the following Python libraries.

Note

When using GSSAPI authentication, you must use a library that links against the MariaDB 10.1.11 or greater C bindings.

SingleStore Python Client

SingleStore recommends using the SingleStore Python Client.

pip install singlestoredb

mysqlclient

Refer to mysqlclient-python for information.

pip install mysqlclient

GSSAPI Authentication Example

You can use GSSAPI authentication via the mysqlclient library. Configure SingleStore to use GSSAPI. See Kerberos Authentication for more information.

To validate, ensure that your MariaDB packages are version 10.1.11 or greater, and that you do not have conflicting MySQL packages:

RHEL MariaDB Version Check

[ec2-user ~]$ rpm -qa | egrep -i 'mysql|maria'
MariaDB-compat-10.2.23-1.el7.centos.x86_64
MariaDB-common-10.2.23-1.el7.centos.x86_64
MariaDB-client-10.2.23-1.el7.centos.x86_64
MariaDB-server-10.2.23-1.el7.centos.x86_64
MariaDB-common-debuginfo-10.2.23-1.el7.centos.x86_64
MariaDB-devel-10.2.23-1.el7.centos.x86_64

GSSAPI authentication has been validated with the mysqlclient-python client library. At the time of writing, there are no known pure python MySQL connector implementations which support the MariaDB GSSAPI client-side protocol.

The following example authenticates to SingleStore via GSSAPI using mysqlclient-python.

Note that the code used to connect for regular connections and Kerberos connections should be the same since the connector is porting the C extensions. This is because the SingleStore server checks grants and sees that the user is authenticated via GSSAPI, and then the client C extensions have an attached handler for GSSAPI, which run independent of the third-party connector.

Add the following code to the gssapi-test.py file:

import MySQLdb
# Substitute 'kerberos_principal_name' and change the host ip as required.
conn = MySQLdb.connect(
user='root',
host='127.0.0.1',
database='information_schema')
if conn:
print("Successfully connected via Kerberos authentication")
cursor = conn.cursor()
query = "SELECT query_text FROM mv_queries"
cursor.execute(query)
for qtext in cursor:
print("{}".format(qtext))
cursor.close()
conn.close()

Here's the output:

[ec2-user ~]$ python gssapi-test.py
Successfully connected via Kerberos authentication
('SELECT @@max_allowed_packet,@@system_time_zone,@@time_zone,@@auto_increment_increment',)
('SELECT @@memsql_id',)
('SELECT @@memsql_version',)
('SELECT ACTIVITY_NAME, QUERY_TEXT, PLAN_WARNINGS, PLAN_INFO FROM INFORMATION_SCHEMA.LMV_QUERIES',)
('SELECT WITH(binary_serialization=1, binary_serialization_internal=1) `_WM_AGG_TABLE`.`AGGREGATOR_ACTIVITY_NAME` AS `aggregator_activity_name`, SUM(`_WM_AGG_TABLE`.`ELAPSED_TIME_MS`) AS `elapsed_time_ms`, SUM(`_WM_AGG_TABLE`.`SUCCESS_COUNT`) AS `numRuns` FROM `_WM_AGG_TABLE` as `_WM_AGG_TABLE` GROUP BY 1 OPTION(NO_QUERY_REWRITE=1, INTERPRETER_MODE=LLVM)',)
('SELECT query_text FROM mv_queries',)
('select query_text from mv_queries',)
('SELECT HEARTBEAT_NO_LOGGING agg.AGGREGATOR_ACTIVITY_NAME, coalesce(sum(leaves.memory_bs)*1000/agg.elapsed_time_ms/0x400/0x400, 0):>bigint,coalesce(agg.elapsed_time_ms/agg.numRuns, @):>bigint as avg_runtime, coalesce(sum(leaves.cpu_time_ms)/agg.numRuns, @):>bigint as avg_cpu_time FROM (select aggregator_activity_name, sum(elapsed_time_ms) as elapsed_time_ms, sum(success_count) as numRuns from information_schema._WM_AGG_TABLE group by 1) agg join information_schema._WM_LEAF_TABLE leaves on agg.aggregator_activity_name = leaves.aggregator_activity_name group by agg.AGGREGATOR_ACTIVITY_NAME',)
('select @@version_comment limit @',)
('SELECT @@memsql_id',)
('SELECT @@memsql_version',)
('SELECT AVAILABILITY_GROUP FROM information_schema.LEAVES\nJOIN information_schema.LMV_NODES\nON information_schema.LEAVES.NODE_ID=information_schema.LMV_NODES.NODE_ID',)
('SELECT WITH(binary_serialization=1, binary_serialization_internal=1) `leaves_0`.`MEMORY_BS` AS `MEMORY_BS`, `leaves_0`.`CPU_TIME_MS` AS `CPU_TIME_MS`, `leaves_0`.`AGGREGATOR_ACTIVITY_NAME` AS `AGGREGATOR_ACTIVITY_NAME` FROM `_WM_LEAF_TABLE` as `leaves_0` OPTION(NO_QUERY_REWRITE=1, INTERPRETER_MODE=LLVM)',)
('SELECT SQL_NO_LOGGING 1',)
('SELECT SQL_NO_LOGGING @@maximum_table_memory, @@maximum_memory',)

PyMySQL

Refer to PyMySQL for information.

pip install PyMySQL

Note

PyMySQL does not support GSSAPI/Kerberos based authentication because this is a pure Python implementation.

MySQL Connector/Python

Caution

The MySQL Connector/Python library is not recommended.

Refer to MySQL Connector/Python for information.

yum install https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-8.0.15-1.el7.x86_64.rpm
yum install https://dev.mysql.com/get/Downloads/Connector-Python/mysql-connector-python-cext-8.0.15-1.el7.x86_64.rpm

Connector

Binary URL

Source Code

MySQL Connector/Python Version 2.1.7 (GPLv2)

Linux RHEL 6 x86_64

2.1.7.zip

MySQL Connector/Python Version 8.0.15 (GPLv2)

Linux RHEL 7 x86_64

Windows x86_64 (Python 2.7)

Windows x86_64 (Python 3.5)

Windows x86_64 (Python 3.6)

Windows x86_64 (Python 3.7)

8.9.15.zip

Last modified: August 24, 2023

Was this article helpful?