Skip to main content

Connector

Connector​

Connector(host='localhost', port=DEFAULT_PORT, user='', password='', token='', use_ssl=True, ca_cert=None, shared_data=None, authenticate=True, use_keepalive=True, verify_hostname=True, retry_interval_seconds=DEFAULT_RETRY_INTERVAL_SECONDS, retry_max_attempts=DEFAULT_RETRY_MAX_ATTEMPTS, config: Optional[Configuration] = None, key: Optional[str] = None, connect: bool = False)

Bases: object

Class to facilitate connections with an instance of ApertureDB

It lets the client execute any JSON query based on the ApertureDB query language specification It manages the TCP connection to the database.

Note

  • The connection is established only when a query is run.
  • A new connection is established for each instance that runs a query, and gets closed explicitly by calling close() or at destruction.

Parameters:

NameTypeDescriptionDefault
hoststr

Address of the host to connect to.

'localhost'
portint

Port to connect to.

DEFAULT_PORT
userstr

Username to specify while establishing a connection.

''
passwordstr

Password to specify while connecting to ApertureDB.

''
tokenstr

Token to use while connecting to the database.

''
use_sslbool

Use SSL to encrypt communication with the database.

True
use_keepalivebool

Set keepalive on the connection with the database. This has two benefits: It reduces the chance of disconnection for a long-running query, and it means that disconnections are detected sooner. Turn this off to reduce traffic on high-cost network connections.

True
configConfiguration

Configuration object to use for connection.

None
keystr

Aperture Key, configuration as a deflated compressed string

None

The Configuration class options: host,port,user,password,token,use_ssl,use_keepalive,retry_interval_seconds,retrun_max_attempts are all ignored in the initializer if a config or key is passed in.

If a key is passed in, it is chosen over a config.

shared_data and authenticate are not Configuration class based options, and have no overrides.

Constructor for the Connector class.

authenticate​

authenticate(shared_data, user, password, token)

Authenticate if this connector and its clones have no shared session. Called automatically by query().

query​

query(q, blobs=[])

Execute a query, authenticating or refreshing the shared session as needed.

If the server rejects the session before executing the query, renew the session and retry the query once. If refresh is rejected, log in again with the configured password or personal token. Permission errors and failures of explicit Authenticate or RefreshToken queries are returned without this automatic retry.

Parameters:

NameTypeDescriptionDefault
qjson

native query to be sent

required
blobslist

Blobs if needed with the query. Defaults to [].

[]

Raises:

TypeDescription
ConnectionError

Fatal error, connection to server lost

Returns:

NameTypeDescription
_type_

description

clone​

clone() -> Connector

Create a new Connector object with the same parameters as the current one. This is important in multi-threaded applications, where each thread should have its own Connector object. Be cautious when using this method, as it will create a new connection to the database, which will consume resources. Ideally, this method should be called once for each thread.

Returns:

NameTypeDescription
ConnectorConnector

Clone of original Connector

check_status​

check_status(json_res: Any) -> int

Returns the status of the first negative command response from the server, or the status of the first command if all are non-negative. Can traverse a JSON recursively to find the statuses.

Parameters:

NameTypeDescriptionDefault
json_resAny

The actual response from the server.

required

Returns:

NameTypeDescription
intint

The value received from the server, or -2 if not found.