The Python client library is a Python package containing components needed to access FeatureBase databases from your Python applications. It provides a simple client class that represents a connection to a FeatureBase database. This connection class exposes a small set of public methods for the application to submit queries against the FeatureBase database.
The following parameters can be used with the client constructor method. All parameters are optional.
| ||Hostname and port number of your FeatureBase instance, it should be passed in || |
| ||Database id of your FeatureBase cloud instance|
| ||Cloud API key that can be used for authn/authz for cloud|
| ||Fully qualified certificate file path|
| ||Fully qualified certificate folder|
| ||Request origin, should be one of the allowed origins defined for your FeatureBase instance|
| ||Number of seconds to wait before timing out on server connection attempts|
Import the FeatureBase library and instantiate a client object by calling the client’s constructor method.
# import the library import featurebase # create a default client that connects to localhost:10101 client = featurebase.client() # create a client that connects to FeatureBase Cloud c_client = featurebase.client( hostport="query.featurebase.com/v2", database="<database_id>", apikey="<APIKey_secret>" )
client.query() method accepts a single SQL query and submits it to the server for execution, it returns a simple result object providing access to data, status and warnings.
result = client.query("SELECT * from demo;") if result.ok: print(result.data)
client.querybatch() method accepts a list of SQL queries and submits them for synchronous or asynchronous execution and returns the results as a list of result objects. By default the queries are synchronously executed one at a time in the input order.
|sqllist||List of SQL queries|
|asynchronous||Boolean flag that indicates whether the SQL statements should be run concurrently or sequentially|| |
|stoponerror||Boolean flag that indicates what to do when a SQL error occurs. Passing || |
Synchronous runs are best suited for executing DDL and DML queries that need to follow specific run orders.
# create a list of SQL statements. sqllist= sqllist.append("CREATE TABLE demo1(_id id, i1 int);") sqllist.append("INSERT INTO demo1(_id, i1) VALUES(1, 100);") sqllist.append("INSERT INTO demo1(_id, i1) VALUES(2, 200);") sqllist.append("select * from demo1;") #submit the list for synchronous execution and #instruct the client to stop when there is an error. results = client.querybatch(sqllist, stoponerror=True) for result in results: if result.ok: print(result.data)
Asynchronous runs are best suited for running SELECT queries that can be run concurrently.
# create a list of SQL statements. sqllist= sqllist.append("SELECT * from demo1;") sqllist.append("SELECT count(*) from demo1;") sqllist.append("SELECT max(i1) from demo1;") #submit the list for asynchronous execution. results = client.querybatch(sqllist, asynchronous=True) for result in results: if result.ok: print(result.data)
Result is a simple data object representing the results of a SQL query. It contains the following attributes.
| ||Boolean indicating query execution status|
| ||Field definitions for the result data|
| ||Data rows returned by the server|
| ||Error information returned by the server|
| ||Warning information returned by the server|
| ||Amount of time (microseconds) it took for the server to execute the SQL|
| ||Number of data rows affected by the SQL statement|