|
1 | 1 | # Python MindsDB SDK |
2 | | -It enables you to connect to a MindsDB server from python using HTTP API. |
3 | 2 |
|
4 | | -## Install |
| 3 | +The Python MindsDB SDK allows you to connect to a MindsDB server from Python using the HTTP API. |
| 4 | + |
| 5 | +## Installation |
| 6 | + |
5 | 7 | ``` |
6 | 8 | pip install mindsdb_sdk |
7 | 9 | ``` |
8 | 10 |
|
9 | 11 | ## Example |
10 | 12 |
|
11 | | -Connect: |
12 | | -```python |
13 | | -import mindsdb_sdk |
| 13 | +### Connecting to the MindsDB server |
| 14 | + |
| 15 | +You can establish a connection to the MindsDB server using the SDK. Here are some examples: |
14 | 16 |
|
15 | | -# Connect to local server |
| 17 | +#### Connect to a local MindsDB server |
16 | 18 |
|
| 19 | +```python |
| 20 | +import mindsdb_sdk |
17 | 21 | server = mindsdb_sdk.connect() |
18 | 22 | server = mindsdb_sdk.connect('http://127.0.0.1:47334') |
| 23 | +``` |
19 | 24 |
|
20 | | -# Connect to cloud server |
| 25 | +#### Connect to the MindsDB Cloud |
21 | 26 |
|
| 27 | +```python |
| 28 | +import mindsdb_sdk |
22 | 29 | server = mindsdb_sdk.connect(email='a@b.com', password='-') |
23 | 30 | server = mindsdb_sdk.connect('https://cloud.mindsdb.com', login='a@b.com', password='-') |
| 31 | +``` |
24 | 32 |
|
25 | | -# Connect to MindsDB Pro |
| 33 | +#### Connect to a MindsDB Pro server |
26 | 34 |
|
| 35 | +```python |
| 36 | +import mindsdb_sdk |
27 | 37 | server = mindsdb_sdk.connect('http://<YOUR_INSTANCE_IP>', login='a@b.com', password='-', is_managed=True) |
28 | | - |
29 | 38 | ``` |
30 | 39 |
|
31 | | -Base usage: |
32 | | -```python |
| 40 | +## Basic usage |
33 | 41 |
|
34 | | -# database |
| 42 | +Once connected to the server, you can perform various operations. Here are some examples: |
| 43 | + |
| 44 | +```python |
| 45 | +# Get a list of databases |
35 | 46 | databases = server.list_databases() |
36 | 47 |
|
37 | | -database = databases[0] # Database type object |
| 48 | +# Get a specific database |
| 49 | +database = databases[0] # Database type object |
38 | 50 |
|
39 | | -# sql query |
| 51 | +# Perform an SQL query |
40 | 52 | query = database.query('select * from table1') |
41 | 53 | print(query.fetch()) |
42 | 54 |
|
43 | | -# create table |
| 55 | +# Create a table |
44 | 56 | table = database.create_table('table2', query) |
45 | 57 |
|
46 | | - |
47 | | -# project |
| 58 | +# Get a project |
48 | 59 | project = server.get_project('proj') |
49 | 60 |
|
50 | | -# sql query |
| 61 | +# Perform an SQL query within a project |
51 | 62 | query = project.query('select * from database.table join model1') |
52 | 63 |
|
53 | | -# create view |
54 | | -view = project.create_view( |
55 | | - 'btc_view', |
56 | | - query=query |
57 | | -) |
| 64 | +# Create a view |
| 65 | +view = project.create_view('view1', query=query) |
58 | 66 |
|
59 | | -# get view |
| 67 | +# Get a list of views |
60 | 68 | views = project.list_views() |
61 | 69 | view = views[0] |
62 | 70 | df = view.fetch() |
63 | 71 |
|
64 | | -# get model |
| 72 | +# Get a list of models |
65 | 73 | models = project.list_models() |
66 | 74 | model = models[0] |
67 | 75 |
|
68 | | -# using model |
| 76 | +# Use a model for prediction |
69 | 77 | result_df = model.predict(df) |
70 | 78 | result_df = model.predict(query) |
71 | 79 |
|
72 | | -# create model |
| 80 | +# Create a model |
| 81 | +timeseries_options = { |
| 82 | + 'order': 'date', |
| 83 | + 'window': 5, |
| 84 | + 'horizon': 1 |
| 85 | +} |
73 | 86 | model = project.create_model( |
74 | | - 'rentals_model', |
75 | | - predict='price', |
76 | | - query=query, |
| 87 | + 'rentals_model', |
| 88 | + predict='price', |
| 89 | + query=query, |
| 90 | + timeseries_options=timeseries_options |
77 | 91 | ) |
78 | 92 |
|
79 | 93 | ``` |
80 | 94 |
|
81 | | -More examples in [Google colab notebook]( |
| 95 | +You can find more examples in this [Google colab notebook]( |
82 | 96 | https://colab.research.google.com/drive/1QouwAR3saFb9ffthrIs1LSH5COzyQa11#scrollTo=k6IbwsKRPQCR |
83 | 97 | ) |
84 | 98 |
|
85 | | -## API documentation |
86 | | - |
87 | | -Api documentation can be found in: |
88 | | -https://mindsdb.github.io/mindsdb_python_sdk/ |
89 | | - |
| 99 | +## API Documentation |
90 | 100 |
|
91 | | -**Generating api docs:** |
| 101 | +The API documentation for the MindsDB SDK can be found at https://mindsdb.github.io/mindsdb_python_sdk/. You can generate the API documentation locally by following these steps: |
92 | 102 |
|
93 | | -Locally: |
| 103 | +### Generating API docs locally: |
94 | 104 |
|
95 | 105 | ```commandline |
96 | 106 | cd docs |
97 | | -
|
98 | 107 | pip install -r requirements.txt |
99 | | -
|
100 | 108 | make html |
101 | 109 | ``` |
102 | 110 |
|
103 | | - |
104 | | -**Online documentation** is updated by pushing in `docs` branch |
| 111 | +The online documentation is automatically updated by pushing changes to the docs branch. |
105 | 112 |
|
106 | 113 |
|
| 114 | +## Testing |
107 | 115 |
|
108 | | -## How to test |
109 | | -` |
110 | | -It runs all tests for components |
| 116 | +To run all the tests for the components, use the following command: |
111 | 117 |
|
112 | 118 | ```bash |
113 | 119 | env PYTHONPATH=./ pytest |
114 | 120 | ``` |
115 | 121 |
|
116 | | -## How to Connect From a Python File |
| 122 | +## Contributing |
117 | 123 |
|
118 | | -Create a file in your python project's root directory to store the connection details: |
| 124 | +We welcome contributions to the MindsDB SDK. If you'd like to contribute, please refer to the contribution guidelines for more information. |
119 | 125 |
|
120 | | -`server.py` |
| 126 | +## License |
121 | 127 |
|
122 | | -Add the connection arguments with **your MindsDB credentials** to `server.py`: |
123 | | - |
124 | | -```python |
125 | | -import mindsdb_sdk |
126 | | - |
127 | | -server = mindsdb_sdk.connect() |
128 | | -server = mindsdb_sdk.connect('http://127.0.0.1:47334') |
129 | | - |
130 | | -server = mindsdb_sdk.connect(email='your_mindsdb_email', password='your_mindsdb_password') |
131 | | -server = mindsdb_sdk.connect('https://cloud.mindsdb.com', email='your_mindsdb_email', password='your_mindsdb_password') |
132 | | -``` |
133 | | - |
134 | | -Open your terminal and type: |
135 | | - |
136 | | -`python server.py` |
137 | | - |
138 | | -### Testing the Connection |
139 | | - |
140 | | -Add test queries to `server.py` with `print()` statements to confirm the connection: |
141 | | - |
142 | | -```python |
143 | | -import mindsdb_sdk #import the mindsdb_sdk package |
144 | | - |
145 | | -server = mindsdb_sdk.connect() |
146 | | -server = mindsdb_sdk.connect('http://127.0.0.1:47334') |
147 | | - |
148 | | -# Input your MindsDB Cloud Credentials below to connect to MindsDB Cloud |
149 | | -server = mindsdb_sdk.connect(email='your_mindsdb_email', password='your_mindsdb_password') |
150 | | -server = mindsdb_sdk.connect('https://cloud.mindsdb.com', email='your_mindsdb_email', password='your_mindsdb_password') # Connect to MindsDB server in the cloud |
151 | | - |
152 | | -databases = server.list_databases() |
153 | | - |
154 | | -database = databases[1] # Database type object |
155 | | - |
156 | | -query = database.query('select * from files.test_data') |
157 | | -print(database) |
158 | | -``` |
| 128 | +The MindsDB SDK is licensed under the MIT License. Feel free to use and modify it according to your needs |
159 | 129 |
|
160 | | -To see a full example, checkout: |
161 | | -`server.py` |
0 commit comments