MindsDB developed the Python SDK that enables users to interact with MindsDB directly from Python code. You can leverage the power of AI in your applications without the need for ETL pipelines or model-serving architecture.
In this blog post, we’ll show you how to use our Python SDK to create and train models directly in Python.
To use MindsDB’s Python SDK, you need to install it via pip, as below:
You can connect to the MindsDB server from Python using HTTP API:
If you installed MindsDB locally via pip or Docker, use the connect method with one argument being your IP address and port. And if you use the MindsDB Cloud account, provide your login and password to connect.
Python SDK provides all methods necessary to interact with databases, tables, projects, models, views, and jobs. These include listing available objects, fetching objects with the get method, creating new objects, making predictions, and more.
Once you store the connection to MindsDB in the server variable, you can use it to fetch one of the connected data sources, like this:
Now let’s get a table stored in this data source:
To get a project, we use again the server variable:
In MindsDB, projects are a natural way to keep artifacts, such as models or views, separate according to what predictive task they solve. You can learn more about MindsDB projects here.
The models, views, and jobs reside within projects. So to list or fetch them, you call the methods on the project variable.
Let’s save one of the models available in the mindsdb project, so we can make predictions:
Here is how to make predictions:
The predict method is called on the model variable. The table variable stores the input data used to make predictions.
Visit our documentation to see more examples of how to use MindsDB’s Python SDK.
If you are already familiar with MinsdDB, we encourage you to try interacting with MindsDB via the Python SDK. It enables you to automate the process of training models and making predictions by running Python code.