Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mindsdb_sdk-1.0.3.tar.gz (13.3 kB view details)

Uploaded Source

File details

Details for the file mindsdb_sdk-1.0.3.tar.gz.

File metadata

  • Download URL: mindsdb_sdk-1.0.3.tar.gz
  • Upload date:
  • Size: 13.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.7.16

File hashes

Hashes for mindsdb_sdk-1.0.3.tar.gz
Algorithm Hash digest
SHA256 934e38caec5f8894c0ee49285e57ae427ca840c562efae57e7291d226314a201
MD5 eb5c03dc7d1bd7f9dd96fe8aa721ab0f
BLAKE2b-256 fb720ece5f4696e617583d96a2032ff98e1d539d8d4459e9bf2379953039a794

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page