MindsDB Python SDK, provides an SDK to use a remote mindsdb instance
Project description
Python MindsDB SDK
It enables you to connect to a MindsDB server from python using HTTP API.
Install
pip install mindsdb_sdk
Example
Connect:
import mindsdb_sdk
# Connect to local server
server = mindsdb_sdk.connect()
server = mindsdb_sdk.connect('http://127.0.0.1:47334')
# Connect to cloud server
server = mindsdb_sdk.connect(email='a@b.com', password='-')
server = mindsdb_sdk.connect('https://cloud.mindsdb.com', login='a@b.com', password='-')
# Connect to MindsDB Pro
server = mindsdb_sdk.connect('http://<YOUR_INSTANCE_IP>', login='a@b.com', password='-', is_managed=True)
Base usage:
# database
databases = server.list_databases()
database = databases[0] # Database type object
# sql query
query = database.query('select * from table1')
print(query.fetch())
# create table
table = database.create_table('table2', query)
# project
project = server.get_project('proj')
# sql query
query = project.query('select * from database.table join model1')
# create view
view = project.create_view(
'btc_view',
query=query
)
# get view
views = project.list_views()
view = views[0]
df = view.fetch()
# get model
models = project.list_models()
model = models[0]
# using model
result_df = model.predict(df)
result_df = model.predict(query)
# create model
model = project.create_model(
'rentals_model',
predict='price',
query=query,
)
More examples in Google colab notebook
API documentation
Api documentation can be found in: https://mindsdb.github.io/mindsdb_python_sdk/
Generating api docs:
Locally:
cd docs
pip install -r requirements.txt
make html
Online documentation is updated by pushing in docs
branch
How to test
` It runs all tests for components
env PYTHONPATH=./ pytest
How to Connect From a Python File
Create a file in your python project's root directory to store the connection details:
server.py
Add the connection arguments with your MindsDB credentials to server.py
:
import mindsdb_sdk
server = mindsdb_sdk.connect()
server = mindsdb_sdk.connect('http://127.0.0.1:47334')
server = mindsdb_sdk.connect(email='your_mindsdb_email', password='your_mindsdb_password')
server = mindsdb_sdk.connect('https://cloud.mindsdb.com', email='your_mindsdb_email', password='your_mindsdb_password')
Open your terminal and type:
python server.py
Testing the Connection
Add test queries to server.py
with print()
statements to confirm the connection:
import mindsdb_sdk #import the mindsdb_sdk package
server = mindsdb_sdk.connect()
server = mindsdb_sdk.connect('http://127.0.0.1:47334')
# Input your MindsDB Cloud Credentials below to connect to MindsDB Cloud
server = mindsdb_sdk.connect(email='your_mindsdb_email', password='your_mindsdb_password')
server = mindsdb_sdk.connect('https://cloud.mindsdb.com', email='your_mindsdb_email', password='your_mindsdb_password') # Connect to MindsDB server in the cloud
databases = server.list_databases()
database = databases[1] # Database type object
query = database.query('select * from files.test_data')
print(database)
To see a full example, checkout:
server.py
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.