Python client library
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 python client library is included in the FeatureBase binary release bundle starting from version
molecula-v5.0.0. You will need to contact us in order to get access to our FeatureBase release server to download the library.
Before you begin
Install python client library
Client object parameters
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|
Create client object
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>" )
Submit a single SQL query
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)
Submit a batch of SQL queries
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 || |
Synchronously run the queries in a batch
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)
Asynchronously run the queries in a batch
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 with a code and description|
| ||Warning information returned by the server|
| ||Amount of time (microseconds) it took for the server to execute the SQL|