API documentation

exception qclient.MalformedQueryException[source]

Raised when the server was unable to process the query because of errors in syntax or semantics.

exception qclient.NoCacheAvailable[source]

Raised when no qcaches are deemed reachable from the currnent node.

class qclient.QClient(node_list, connect_timeout=1.0, read_timeout=2.0, verify=True, cert=None, auth=None, consecutive_error_count_limit=10)[source]

Main client class.

Basic example:

>>> client = QClient(node_list=('http://host1:9401', 'http://host2:9401', 'http://host3:9401'))
>>> result = client.get('someKey', {'select': ['col1', 'col2', 'col3'], 'where': ['<', 'col', 1]})
Parameters:
  • node_list – List or other iterables with addresses to qcache servers. Eg. [‘http://host1:9401‘, ‘http://host2:9401‘]
  • connect_timeout – Number of seconds to wait until connection timeout occurs.
  • read_timeout – Number of seconds to wait until read timeout occurs.
  • verify – If https is used controls if the host certificate should be verified.
  • auth – Tuple (username, password), used for basic auth.
  • consecutive_error_count_limit – Number of times to retry operations before giving up.
delete(key)[source]

Delete table stored under key from QCache.

NOTE: If more than one QCache node is used there is no guarantee that the table is completely removed

since it may be stored in multiple location depending events.

Example: A small installation with two Qaches, qc1 and qc2. Table t1 is stored on qc1. qc1 disappears for unknown reason. t1 is then stored and read from t2 instead. Later t1 comes back. Data is now read from qc1 instead. A delete would in this case be issued against qc1, after the delete qc2 would still hold a copy of t1.

Parameters:

key – Key for the table to delete

Raises:
Returns:

None

get(key, q, accept='application/json', post_query=False, query_headers=None)[source]

Execute query and return result.

Parameters:
  • key – Key for the table to query.
  • q – Dict with the query as described in the QCache documentation
  • accept – Response type, application/json and text/csv are supported
  • post_query – If set the query will be executed using a POST rather than GET. Good for very large queries.
  • query_headers – dict with additional headers to include when issuing query. Key - header name Value - header value
Returns QueryResult:
 

Contains the result of the query.

Raises:
post(key, content, content_type='text/csv', post_headers=None)[source]

Post table data to QCache for key.

Parameters:
  • key – Key to store the table under
  • content – Byte string with content encoded either as CSV or JSON.
  • content_type – application/json or text/csv depending on uploaded content
  • post_headers – dict with additional headers to include. Key - header name Value - header value
Returns:

None

Raises:
query(key, q, load_fn, load_fn_kwargs=None, content_type='text/csv', accept='application/json', post_headers=None, post_query=False, query_headers=None)[source]

Convenience method to query for data. If the requested key is not available in the QCache a call will be made to :load_fn: providing :load_fn_kwargs: as key value args. :load_fn: should return the data to insert into QCache. Once the data has been pushed to QCache the query in executed again against the newly created table.

Parameters:
  • key – Key for the table to query.
  • q – Dict with the query as described in the QCache documentation
  • load_fn – Function called to fetch data if not present in QCache.
  • load_fn_kwargs – Key-value arguments to load_fn
  • content_type – application/json or text/csv depending on uploaded content
  • accept – Response type, application/json and text/csv are supported
  • post_headers – dict with additional headers to include when pushing data to the caches. Key - header name Value - header value
  • post_query – If set the query will be executed using a POST rather than GET. Good for very large queries.
  • query_headers – dict with additional headers to include when issuing query. Key - header name Value - header value
Returns:

QueryResult: Contains the result of the query.

Raises:
exception qclient.QClientException[source]

Base exception for all other exceptions raised in QClient

class qclient.QueryResult(response)[source]

Returned upon successful query response.

Parameters:
  • content – A byte string containing the body received from the server.
  • unsliced_result_len – contains the complete result length. If no slicing/pagination is applied this will equal the number of records returned.
  • encoding – Content-Encoding as set by the server
exception qclient.TooManyConsecutiveErrors[source]

Raised to when operations have been retried too many times. This is done to avoid overloading resources with failing requests. If raised it’s probably an indicator of some misconfiguration or network problem.

exception qclient.UnexpectedServerResponse[source]

Raised when the QCache server responded with an HTTP code that could not be interpreted.

exception qclient.UnsupportedAcceptType[source]

Raised when the server cannot produce a response of the requested type.