QldbDriver Reference

class pyqldb.driver.qldb_driver.QldbDriver(ledger_name, retry_config=None, read_ahead=0, executor=None, region_name=None, verify=None, endpoint_url=None, aws_access_key_id=None, aws_secret_access_key=None, aws_session_token=None, config=None, boto3_session=None, max_concurrent_transactions=0)[source]

Creates a QldbDriver instance that can be used to execute transactions against Amazon QLDB. A single instance of the QldbDriver is always attached to one ledger, as specified in the ledgerName parameter.

Parameters:
  • ledger_name (str) – The QLDB ledger name.

  • retry_config (pyqldb.config.retry_config.RetryConfig) – Config to specify max number of retries, base and custom backoff strategy for retries. Will be overridden if a different retry_config is passed to pyqldb.driver.qldb_driver.QldbDriver.execute_lambda().

  • read_ahead (int) – The number of read-ahead buffers. Determines the maximum number of statement result pages that can be buffered in memory. This value must be either 0, to disable read-ahead, or a minimum of 2.

  • executor (concurrent.futures.thread.ThreadPoolExecutor) – A specific, optional, executor to be used by the retrieval thread if read-ahead is enabled.

  • region_name (str) – See [1].

  • verify (bool/str) – See [1].

  • endpoint_url (str) – See [1].

  • aws_access_key_id (str) – See [1].

  • aws_secret_access_key (str) – See [1].

  • aws_session_token (str) – See [1].

  • config (botocore.config.Config) – See [2]. Note that parameter user_agent_extra will be appended and retries will be overwritten.

  • boto3_session (boto3.session.Session) – The boto3 session to create the client with (see [1]). The boto3 session is expected to be configured correctly.

  • max_concurrent_transactions (int) – Specifies the maximum number of concurrent transactions that can be executed by the driver. It is required that the property max_pool_connections in :param config be set equal to :param max_concurrent_transactions. Set to 0 to use the maximum possible amount allowed by the client configuration. See :param config.

Raises:
  • TypeError – When config is not an instance of botocore.config.Config. When boto3_session is not an instance of boto3.session.Session. When retry_config is not an instance of pyqldb.config.retry_config.RetryConfig.

  • ValueError – When max_concurrent_transactions exceeds the limit set by the client. When max_concurrent_transactions is negative. When read_ahead is not set to the specified allowed values.

[1]: Boto3 Session.client Reference.

[2]: Botocore Config Reference.

close()[source]

Close the driver and any sessions in the pool.

execute_lambda(query_lambda, retry_config=None)[source]

Execute the lambda function against QLDB within a transaction and retrieve the result. It will retry up to the retry limit if an OCC conflict or retryable exception occurs. This is the primary method to execute a transaction against Amazon QLDB ledger.

Parameters:
  • query_lambda (function) – The lambda function to execute. The function receives an instance of pyqldb.execution.executor.Executor which can be used to execute statements. The instance of pyqldb.execution.executor.Executor wraps an implicitly created transaction. The transaction will be implicitly committed when the passed function returns. The lambda function cannot have any side effects as it may be invoked multiple times, and the result cannot be trusted until the transaction is committed.

  • retry_config (pyqldb.config.retry_config.RetryConfig) – Config to specify max number of retries, base and custom backoff strategy for retries. This config overrides the retry config set at driver level for a particular lambda execution. Note that all the values of the driver level retry config will be overwritten by the new config passed here.

Return type:

pyqldb.cursor.buffered_cursor.BufferedCursor/object

Returns:

The return value of the lambda function which could be a pyqldb.cursor.buffered_cursor.BufferedCursor on the result set of a statement within the lambda.

Raises:
list_tables()[source]

Get the list of table names in the ledger.

Return type:

pyqldb.cursor.buffered_cursor.BufferedCursor

Returns:

Iterable of table names in amazon.ion.simple_types.IonPyText format found in the ledger.

Raises:

DriverClosedError – When this driver is closed.

property read_ahead

The number of read-ahead buffers to be made available per StreamCursor instantiated by this driver. Determines the maximum number of result pages that can be buffered in memory.

property retry_limit

The number of automatic retries for statement executions using convenience methods on sessions when an OCC conflict or retryable exception occurs.