CREATE DATABASE
statement. So you can reach data from any application that has its handler implemented within MindsDB.
APIHandler
class.
By providing the implementation for some or all of the methods contained in the APIHandler
class, you can interact with the application APIs.
__init__()
method, there are five core methods that must be implemented. We recommend checking actual examples in the codebase to get an idea of what goes into each of these methods, as they can change a bit depending on the nature of the system being integrated.
Let’s review the purpose of each method.
Method | Purpose |
---|---|
_register_table() | It registers the data resource in memory. For example, if you are using Twitter API it registers the tweets resource from /api/v2/tweets . |
connect() | It performs the necessary steps to connect/authenticate to the underlying system. |
check_connection() | It evaluates if the connection is alive and healthy. |
native_query() | It parses any native statement string and acts upon it (for example, raw syntax commands). |
call_application_api() | It calls the application API and maps the data to pandas DataFrame. This method handles the pagination and data mapping. |
mindsdb.integrations.utilities
library, contributors can find various methods that may be useful while implementing new handlers._register_table()
method, you can use it to map to the APITable
class.
The APITable
class provides CRUD methods.
Method | Purpose | |
---|---|---|
select() | It implements the mappings from the ast.Select and calls the actual API through the call_application_api . | |
insert() | It implements the mappings from the ast.Insert and calls the actual API through the call_application_api . | |
update() | It implements the mappings from the ast.Update and calls the actual API through the call_application_api . | |
delete() | It implements the mappings from the ast.Delete and calls the actual API through the call_application_api . | |
add() | Adds new row to the data dictionary. | |
list() | List data based on certain conditions by providing FilterCondition, limits, sorting and target fields. | |
get_columns() | It maps the data columns returned by the API. |
APIHandler
class.
Here is a step-by-step guide:
__init__()
method:
This method initializes the handler.
connect()
method:
The connect()
method sets up the connection.
check_connection()
method:
The check_connection()
method performs the health check for the connection.
native_query()
method:
The native_query()
method runs commands of the native API syntax.
call_application_api()
method:
This method makes the API calls. It is not mandatory to implement this method, but it can help make the code more reliable and readable.
connection_args
Dictionaryconnection_args
dictionary contains all of the arguments used to establish the connection along with their descriptions, types, labels, and whether they are required or not.
Here is an example of the connection_args
dictionary from the GitHub handler:
connection_args_example
Dictionaryconnection_args_example
dictionary contains an example of all required arguments to establish the connection.
Here is an example of the connection_args_example
dictionary from the GitHub handler.
__init__.py
file of the handler:
Handler
class.version
of the handler.name
of the handler.type
of the handler, either DATA
handler or ML
handler.icon_path
to the file with the database icon.title
of the handler or a short description.description
of the handler.connection_args
dictionary with the connection arguments.connection_args_example
dictionary with an example of the connection arguments.import_error
message that is used if the import of the Handler
class fails.__about__.py
. This file is imported into the __init__.py
file.
Here is an example of the __init__.py
file for the GitHub handler.
__about__.py
file for the same GitHub handler contains the following variables: