|
| 1 | +# Minds Legacy SDK (v1.x) |
| 2 | + |
| 3 | +> **⚠️ API Version Notice** |
| 4 | +> |
| 5 | +> This documentation applies to the **legacy SDK version** used for connecting to the **Minds Demo environment** at https://demo.mdb.ai. |
| 6 | +> |
| 7 | +> For users of the **current Minds Cloud environments**, please refer to the [main documentation](README.md) for compatibility. |
| 8 | +> |
| 9 | +> **Legacy Version**: v1.x (For Minds Demo environment) |
| 10 | +> **Current Version**: v2.x+ ([Current Documentation](README.md)) |
| 11 | +
|
| 12 | +### Installation |
| 13 | + |
| 14 | +To install the SDK, use pip: |
| 15 | + |
| 16 | +```bash |
| 17 | +pip install minds-sdk==1.3.3 |
| 18 | +``` |
| 19 | + |
| 20 | +### Getting Started |
| 21 | + |
| 22 | +1. Initialize the Client |
| 23 | + |
| 24 | +To get started, you'll need to initialize the Client with your API key. If you're using a different server, you can also specify a custom base URL. |
| 25 | + |
| 26 | +```python |
| 27 | +from minds.client import Client |
| 28 | + |
| 29 | +# Default connection to Minds Cloud that uses 'https://mdb.ai' as the base URL |
| 30 | +client = Client("YOUR_API_KEY") |
| 31 | + |
| 32 | +# If you have self-hosted Minds Cloud instance, use your custom base URL |
| 33 | +base_url = 'https://<custom_cloud>.mdb.ai/' |
| 34 | +client = Client("YOUR_API_KEY", base_url) |
| 35 | +``` |
| 36 | + |
| 37 | +2. Creating a Data Source |
| 38 | + |
| 39 | +You can connect to various databases, such as PostgreSQL, by configuring your data source. Use the DatabaseConfig to define the connection details for your data source. |
| 40 | + |
| 41 | +```python |
| 42 | + |
| 43 | +from minds.datasources import DatabaseConfig |
| 44 | + |
| 45 | +postgres_config = DatabaseConfig( |
| 46 | + name='my_datasource', |
| 47 | + description='<DESCRIPTION-OF-YOUR-DATA>', |
| 48 | + engine='postgres', |
| 49 | + connection_data={ |
| 50 | + 'user': 'demo_user', |
| 51 | + 'password': 'demo_password', |
| 52 | + 'host': 'samples.mindsdb.com', |
| 53 | + 'port': 5432, |
| 54 | + 'database': 'demo', |
| 55 | + 'schema': 'demo_data' |
| 56 | + }, |
| 57 | + tables=['<TABLE-1>', '<TABLE-2>'] |
| 58 | +) |
| 59 | +``` |
| 60 | + |
| 61 | +3. Creating a Mind |
| 62 | + |
| 63 | +You can create a `mind` and associate it with a data source. |
| 64 | + |
| 65 | +```python |
| 66 | + |
| 67 | +# Create a mind with a data source |
| 68 | +mind = client.minds.create(name='mind_name', datasources=[postgres_config]) |
| 69 | + |
| 70 | +# Alternatively, create a data source separately and add it to a mind later |
| 71 | +datasource = client.datasources.create(postgres_config) |
| 72 | +mind2 = client.minds.create(name='mind_name', datasources=[datasource]) |
| 73 | +``` |
| 74 | + |
| 75 | +You can also add a data source to an existing mind: |
| 76 | + |
| 77 | +```python |
| 78 | + |
| 79 | +# Create a mind without a data source |
| 80 | +mind3 = client.minds.create(name='mind_name') |
| 81 | + |
| 82 | +# Add a data source to the mind |
| 83 | +mind3.add_datasource(postgres_config) # Using the config |
| 84 | +mind3.add_datasource(datasource) # Using the data source object |
| 85 | +``` |
| 86 | + |
| 87 | +Create mind with tables restriction for datasource: |
| 88 | +```python |
| 89 | +from minds.datasources.datasources import DatabaseTables |
| 90 | +datasource = DatabaseTables( |
| 91 | + name='my_db', |
| 92 | + tables=['table1', 'table1'], |
| 93 | +) |
| 94 | +mind4 = client.minds.create(name='mind_name', datasources=[datasource]) |
| 95 | +``` |
| 96 | + |
| 97 | + |
| 98 | +### Managing Minds |
| 99 | + |
| 100 | +You can create a mind or replace an existing one with the same name. |
| 101 | + |
| 102 | +```python |
| 103 | + |
| 104 | +mind = client.minds.create(name='mind_name', replace=True, datasources=[postgres_config]) |
| 105 | +``` |
| 106 | + |
| 107 | +To update a mind, specify the new name and data sources. The provided data sources will replace the existing ones. |
| 108 | + |
| 109 | +```python |
| 110 | + |
| 111 | +mind.update( |
| 112 | + name='mind_name', |
| 113 | + datasources=[postgres_config] |
| 114 | +) |
| 115 | +``` |
| 116 | + |
| 117 | +#### List Minds |
| 118 | + |
| 119 | +You can list all the minds you’ve created. |
| 120 | + |
| 121 | +```python |
| 122 | + |
| 123 | +print(client.minds.list()) |
| 124 | +``` |
| 125 | + |
| 126 | +#### Get a Mind by Name |
| 127 | + |
| 128 | +You can fetch details of a mind by its name. |
| 129 | + |
| 130 | +```python |
| 131 | + |
| 132 | +mind = client.minds.get('mind_name') |
| 133 | +``` |
| 134 | + |
| 135 | +#### Remove a Mind |
| 136 | + |
| 137 | +To delete a mind, use the following command: |
| 138 | + |
| 139 | +```python |
| 140 | + |
| 141 | +client.minds.drop('mind_name') |
| 142 | +``` |
| 143 | + |
| 144 | +### Managing Data Sources |
| 145 | + |
| 146 | +To view all data sources: |
| 147 | + |
| 148 | +```python |
| 149 | + |
| 150 | +print(client.datasources.list()) |
| 151 | +``` |
| 152 | + |
| 153 | +#### Get a Data Source by Name |
| 154 | + |
| 155 | +You can fetch details of a specific data source by its name. |
| 156 | + |
| 157 | +```python |
| 158 | + |
| 159 | +datasource = client.datasources.get('my_datasource') |
| 160 | +``` |
| 161 | + |
| 162 | +#### Remove a Data Source |
| 163 | + |
| 164 | +To delete a data source, use the following command: |
| 165 | + |
| 166 | +```python |
| 167 | + |
| 168 | +client.datasources.drop('my_datasource') |
| 169 | +``` |
| 170 | +>Note: The SDK currently does not support automatically removing a data source if it is no longer connected to any mind. |
| 171 | +
|
| 172 | +### Community Supported SDKs |
| 173 | + |
| 174 | +- [Java-SDK](https://github.com/Better-Boy/minds-java-sdk) |
| 175 | +- [Ruby-SDK](https://github.com/tungnt1203/minds_ruby_sdk) |
| 176 | +- [Dart-SDK](https://github.com/ArnavK-09/mdb_dart) |
| 177 | +- [Javascript](https://github.com/scshiv29-dev/mindsbd_sdk_js) |
| 178 | +- [C# SDK](https://github.com/priyanshuverma-dev/Minds.SDK) |
| 179 | +- [Go SDK](https://github.com/Abiji-2020/minds-go-sdk) |
| 180 | + |
| 181 | +#### Command Line Tools |
| 182 | +- [Minds CLI](https://github.com/Better-Boy/minds-cli-sdk) |
| 183 | + |
0 commit comments