Models

exception composapy.queryview.models.KeyRequiredException
exception composapy.queryview.models.QueryException
exception composapy.queryview.models.QueryInputException
class composapy.queryview.models.QueryViewObject(contract: <module 'CompAnalytics.Contracts.QueryView'>, timeout=None, validate_query=False)

Wrapper for the QueryView.QueryView contract.

from composapy.key.api import Key
from composapy.queryview.api import QueryView

key = Key.get(123456)  # KeyObject(id=123456)

# create driver and connect...
driver = QueryView.driver()  # QueryViewObject(name=some_name, key=None)
driver.connect(key)

# ...or use the key as method argument to automatically connect
driver = QueryView.driver(key)  # QueryViewObject(name=some_name, key=some_key)
connect(key: KeyObject) None

Set new key and update contract DbConnectionId.

from composapy.key.api import Key
from composapy.queryview.api import QueryView

key = Key.get(123456)  # KeyObject(id=123456)

driver = QueryView.driver()  # QueryViewObject(name=some_name, key=None)
driver.connect(key)
print(driver)  # QueryViewObject(name=some_name, key=some_name)
Parameters:

key – KeyObject retrieved with the Composable Key api

property connection_info: Dict[str, Any]

Returns KeyObject attribute information.

get_driver_timeout()

Get the current QueryTimeout value for the query driver (in seconds).

property key: KeyObject

Returns the connected KeyObject.

property name: str

Returns the contract name.

run(query: str, timeout: int = None, validate_query: bool = None) DataFrame

Run a query on the connected database, returning a Pandas DataFrame of the results.

df = driver.run("select column_name_1, column_name_2 from my_table")
Parameters:
  • query – The query string

  • timeout – If specified, this integer timeout (in seconds) will be used as the QueryTimeout value, overriding the default timeout and the timeout specified when the driver was created.

  • validate_query – If specified, this boolean indicates whether to apply a pre-compilation step to validate SQL queries run with the driver, overriding the validation setting specified when the driver was created. This often provides more informative error output but can be disabled for maximal query performance.

set_driver_timeout(timeout: int)

Set the QueryTimeout value for the query driver (in seconds).

class composapy.queryview.models.QueryViewPagedObject(contract: <module 'CompAnalytics.Contracts.QueryView'>, timeout=None, validate_query=False, saved=False)
run(query: str, timeout: int = None, validate_query: bool = None) ITableResult

Run a query on the connected database, returning a Pandas DataFrame of the results.

df = driver.run("select column_name_1, column_name_2 from my_table")
Parameters:
  • query – The query string

  • timeout – If specified, this integer timeout (in seconds) will be used as the QueryTimeout value, overriding the default timeout and the timeout specified when the driver was created.

  • validate_query – If specified, this boolean indicates whether to apply a pre-compilation step to validate SQL queries run with the driver, overriding the validation setting specified when the driver was created. This often provides more informative error output but can be disabled for maximal query performance.