stpy.ds package

Submodules

stpy.ds.connection module

class stpy.ds.connection.Connection(url, dataspace, username, password, autocommit=True, timeout=30, ssl=None)

Bases: object

autocommit(on)

Enables/disables autocommit.

Parameters:on – bool
close()

Close the connection now (rather than whenever .__del__() is called).

The connection will be unusable from this point forward; an Error (or subclass) exception will be raised if any operation is attempted with the connection. The same applies to all cursor objects trying to use the connection. Note that closing a connection without committing the changes first will cause an implicit rollback to be performed.

commit()

Commits any pending transaction to the database. If there is no any started transaction this method successfully does nothing.

cursor()

Return a new Cursor Object using the connection. :return: Cursor

errorhandler(connection, cursor, errorclass, errorvalue)

If cursor is not None, (errorclass, errorvalue) is appended to cursor.messages; otherwise it is appended to connection.messages. Then errorclass is raised with errorvalue as the value.

You can override this with your own error handler by assigning it to the instance.

get_autocommit()

Returns autocommit enabled/disable. :return: bool

get_downloadable_lob_size()

Returns max downloadable lob size in bytes. :param size: :return:

get_type_factory()

Returns TypeFactory reference. :return: TypeFactory reference

import_semantic_type(name)

Imports semantic type from dataspace runtime to this connection. After semantic type has been imported objects of this type will be automatically serialized to object of this type and objects of this type can be created using TypeFactory. :param name: semantic type name

rollback()

Rollback dataspace transaction if any started. If autocommit is enabled raises exception.

set_downloadable_lob_size(size)

Sets maximum downloadable lob size in bytes. This size defines maximum amount of bytes that should be downloaded to client on first call.

-1 means download full lob data on first call :param size: :return:

stpy.ds.connection.defaulterrorhandler(connection, cursor, errorclass, errorvalue)

If cursor is not None, (errorclass, errorvalue) is appended to cursor.messages; otherwise it is appended to connection.messages. Then errorclass is raised with errorvalue as the value.

You can override this with your own error handler by assigning it to the instance.

stpy.ds.cursor module

class stpy.ds.cursor.Cursor(connection)

Bases: object

Cursor attributes
.description

This read-only attribute is a sequence of 7-item sequences. Each of these sequences contains information describing one result column:

name type_code display_size internal_size precision scale null_ok

The first two items ( name and type_code ) are mandatory, the other five are optional and are set to None if no meaningful values can be provided.

This attribute will be None for operations that do not return rows or if the cursor has not had an operation invoked via the .execute*() method yet.

The type_code can be interpreted by comparing it to the Type Objects specified in the section below.

.rowcount

This read-only attribute specifies the number of rows that the last .execute*() produced (for DQL statements like SELECT ) or affected (for DML statements like UPDATE or INSERT ).

The attribute is None in case no .execute*() has been performed on the cursor or the rowcount of the last operation cannot be determined by the interface.

.arraysize
Defines the fetch size used to fetch rows from server, default one row. Also defines default number of rows fetchmany() will fetch. This value should be set before callproc() or execute() call. A value of 0 or -1 means fetch all rows in first call.
callproc(funcname, parameters=None)

Call a stored dataspace function with the given name. The sequence of parameters must contain one entry for each argument that the procedure expects. The operation uses .arraysize value as fetch size to fetch rows from server.

Function returns passed parameters. Function results can be accessed through the standard .fetch*() methods.

Parameters:
  • funcname – procedure name
  • parameters – arguments
Returns:

close()

Closes the cursor. Future operations raise ProgrammingError. If you are using fetch size, it is very important to close the cursor when you are done with it and before creating a new one. :return:

execute(query, parameters=None)

Prepare and execute a database operation (query or command). Operations and parameters should be in question mark format. Parameters may be provided as sequenxe or array. The operation uses .arraysize value as fetch size to fetch rows from server.

A reference to the operation will be retained by the cursor. If the same operation object is passed in again, then the cursor can optimize its behavior. This is most effective for algorithms where the same operation is used, but different parameters are bound to it (many times).

For maximum efficiency when reusing an operation, it is best to use the .setinputsizes() method to specify the parameter types and sizes ahead of time.

Parameters:
  • query – DSQL query in question mark format
  • parameters – list of parameters of query
Returns:

executemany(operation, *seq_of_parameters)

NOT SUPPORTED

fetchall()

Fetch all (remaining) rows of a query result, returning them as a sequence of sequences (e.g. a list of tuples). Note that the cursor’s arraysize attribute can affect the performance of this operation.

An OperationalError exception is raised if the previous call to .execute*() did not produce any result set or no call was issued yet. :return: sequence of tuples

fetchmany(size=None)

Fetch the next set of rows of a query result, returning a sequence of sequences (e.g. a list of tuples). An empty sequence is returned when no more rows are available.

The number of rows to fetch per call is specified by the parameter. If it is not given, the cursor’s .arraysize determines the number of rows to be fetched. The method should try to fetch as many rows as indicated by the size parameter. If this is not possible due to the specified number of rows not being available, fewer rows may be returned.

The operation uses .arraysize value as fetch size to fetch rows from server.

An OperationalError exception is raised if the previous call to .execute*() did not produce any result set or no call was issued yet.

Note there are performance considerations involved with the size parameter. For optimal performance, it is usually best to use the .arraysize attribute. If the size parameter is used, then it is best for it to retain the same value from one .fetchmany() call to the next.

Parameters:size – maximum number of rows to fetch, 0 or negative values mean fetch all rows
Returns:sequence of tuples or empty sequence
fetchone()

Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. The operation uses .arraysize value as fetch size to fetch rows from server.

An OperationalError exception is raised if the previous call to .execute*() did not produce any result set or no call was issued yet.

Returns:tuple or None
next()

Fetch the next row of a query result set, returning a single sequence, or None when no more data is available. The operation uses .arraysize value as fetch size to fetch rows from server.

An OperationalError exception is raised if the previous call to .execute*() did not produce any result set or no call was issued yet.

Returns:tuple or None
nextset()

NOT SUPPORTED

scroll(count, mode='relative')

Scroll the cursor in the result set to a new position according to mode .

If mode is relative (default), value is taken as offset to the current position in the result set, if set to absolute , value states an absolute target position.

Parameters:
  • count – rows count to scroll
  • mode – relative - scroll count rows from current position, absolute - scroll count rows from rowset begining
Returns:

Row on the scrolled position, None if position out of the row set

setinputsizes(*args)

Does nothing, required by API.

setoutputsizes(*args)

Does nothing, required by API.

stpy.ds.ds module

stpy.ds.ds.Binary(x)
class stpy.ds.ds.DBAPISet

Bases: frozenset

A special type of set for which A == x is true if A is a DBAPISet and x is a member of that set.

stpy.ds.ds.connect(url, dataspace, username, password, autocommit=True, timeout=30, ssl=None)

Creates a connection to the dataspace.

url
string, URL of the node to connect to in format http[s]://<host>:<port>
dataspace
string, dataspace to connect to in format <DataspaceType>.<DataspaceName>
username
string, user to connect as
password
string, password to use
autocommit
If True (default), autocommit is enabled. If False, autocommit is disabled. If None, autocommit isn’t set and server default is used.
timeout
http timeout in seconds.
ssl
dictionary with SSL connection parameters:
  • cert_reqs - specifies whether a certificate is required from the other side of the connection, and whether it will be validated if provided.
    Should be one of the following values:
    • CERT_NONE or None - certificates ignored
    • CERT_OPTIONAL - not required, but validated if provided
    • CERT_REQUIRED - required and validated

    If the value of this parameter is not CERT_NONE, then the ca_certs parameter must point to a file of CA certificates.

  • ca_certs - file contains a set of concatenated ‘certification authority’ certificates, which are used to validate

    certificates passed from the other end of the connection.

  • ca_cert_dir - a directory containing CA certificates in multiple separate files, as supported by OpenSSL’s -CApath flag or

    the capath argument to SSLContext.load_verify_locations().

  • ssl_version - specifies which version of the SSL protocol to use. Optional.

  • key_file and cert_file - optional files which contain a certificate to be used to identify the local side of the connection.

  • disable_warnings - specifies disable or not InsecureRequestWarning warning, by default True.

stpy.ds.ds.define_type(type)

stpy.ds.exceptions module

exception stpy.ds.exceptions.DSError(message, cause=None)

Bases: exceptions.StandardError

Exception related to operation with Dataspace.

exception stpy.ds.exceptions.DataError(message, cause=None)

Bases: stpy.ds.exceptions.DatabaseError

Exception raised for errors that are due to problems with the processed data like division by zero, numeric value out of range, etc.

exception stpy.ds.exceptions.DatabaseError(message, cause=None)

Bases: stpy.ds.exceptions.Error

Exception raised for errors that are related to the database.

exception stpy.ds.exceptions.Error(message, cause=None)

Bases: stpy.ds.exceptions.DSError

Exception that is the base class of all other error exceptions (not Warning).

exception stpy.ds.exceptions.IntegrityError(message, cause=None)

Bases: stpy.ds.exceptions.DatabaseError

Exception raised when the relational integrity of the database is affected, e.g. a foreign key check fails, duplicate key, etc.

exception stpy.ds.exceptions.InterfaceError(message, cause=None)

Bases: stpy.ds.exceptions.Error

Exception raised for errors that are related to the database interface rather than the database itself.

exception stpy.ds.exceptions.InternalError(message, cause=None)

Bases: stpy.ds.exceptions.DatabaseError

Exception raised when the database encounters an internal error, e.g. the cursor is not valid anymore, the transaction is out of sync, etc.

exception stpy.ds.exceptions.NotSupportedError(message, cause=None)

Bases: stpy.ds.exceptions.DatabaseError

Exception raised in case a method or database API was used which is not supported by the database, e.g. requesting a .rollback() on a connection that does not support transaction or has transactions turned off.

exception stpy.ds.exceptions.OperationalError(message, cause=None)

Bases: stpy.ds.exceptions.DatabaseError

Exception raised for errors that are related to the database’s operation and not necessarily under the control of the programmer, e.g. an unexpected disconnect occurs, the data source name is not found, a transaction could not be processed, a memory allocation error occurred during processing, etc.

exception stpy.ds.exceptions.ProgrammingError(message, cause=None)

Bases: stpy.ds.exceptions.DatabaseError

Exception raised for programming errors, e.g. table not found or already exists, syntax error in the SQL statement, wrong number of parameters specified, etc.

exception stpy.ds.exceptions.Warning(message, cause=None)

Bases: exceptions.Warning, stpy.ds.exceptions.DSError

Exception raised for important warnings like data truncations while inserting, etc.

stpy.ds.times module

stpy.ds.times.DateFromTicks(ticks)
stpy.ds.times.TimeFromTicks(ticks)
stpy.ds.times.TimestampFromTicks(ticks)