Python API Reference Guide

The Python API Reference Guide describes the following:

Overview

The SQream Python connector allows Python programs to connect to SQream, and conforms to Python DB-API specifications PEP-249. The main Python connector module is pysqream, which contains the connection class.

The following is the syntax for the connect class:

$ connect(host, port, database, username, password, clustered = False, use_ssl = False, service='sqream', reconnect_attempts=3, reconnect_interval=10)

The Connection class creates a new Connection object and connects to SQream.

The following table describes the connect object parameters:

Parameter

Description

host

Sets the SQream hostname or IP.

port

Sets the SQream port.

database

Sets the database name.

username

Sets the username for establishing a connection.

password

Sets the password used with your username.

clustered

Connects using either the load balancer or direct to worker (Default: false - direct to worker).

use_ssl

Uses an SSL connection (default: false).

service

(Optional) Sets the service queue (default: ‘sqream’).

reconnect_attempts

Sets the number of failed reconnection attempts to attempt before closing the connection.

reconnect_interval

Sets the time in seconds between reconnection attempts.

Connection Object Parameters

The following table describes the Connection class parameters:

Parameter

Description

arraysize

Specifies the number of rows to fetch at a time using fetchmany(). Default - 1.

rowcount

Not used. Return -1.

description

Displays read-only attributes containing the following result set metadata:

  • name - Displays the column name.

  • type_code - Displays the internal type code.

  • display_size - Not used, identical to internal_size below.

  • internal_size - Displays the Data size (bytes).

  • precision - Not used. Displays the precision of numeric data.

  • scale - Not used. Displays the scale for numeric data.

  • null_ok - Specifices whether NULL values are allowed for the column.

execute

Executes statements (self, query, params=None). Parameters are not supported.

executemany

Prepares a statement and executes it against all parameter sequences found in rows_or_cols (self, query, rows_or_cols=None, data_as=’rows’, amount=None).

  • self - Connection Object Parameters.

  • query - INSERT statement.

  • rows_or_cols - Data buffer to insert. This should be a sequence of lists or tuples..

  • data_as - (Optional) Read data as rows or columns.

  • amount - (Optional) count of rows to insert.

close

Closes a statement and connection (self). Closed statements must be reopened by creating a new cursor.

cursor

Creates a new Connection Object Parameters cursor (self). Recommended - create a new cursor for every statement.

fetchall

Fetches all remaining records from the result set (self, data_as=’rows’). Returns an empty sequence if no more rows are available.

fetchone

Fetches one record from the result set. Returns an empty sequence if no more rows are available.

  • self - Connection Object Parameters.

  • size - Sets the number of records to fetch. If not set, fetches Connection.arraysize records (default = 1).

  • data_as - (Optional) Reads data as rows or columns.

__iter__()

Makes the cursor iterable.

API Level Object Parameters

The API Level object parameter is a string constant stating the supported API level. The Python connector supports apilevel 2.0.

Thread Safety Object Parameters

The Thread Safety object parameter displays the thread safety level the interface supports. The Python connector currently supports threadsafety level 1, which states that threads can share the module, but not connections.

Parameter Style Object Parameters

The paramstyle object parameter sets the placeholder marker and is set to to qmark, which is a question mark (?).