Skip to content

Commit e3f623e

Browse files
authored
Merge pull request #62 from mindsdb/staging
Release 1.0.5
2 parents 45aad68 + 26d7c34 commit e3f623e

File tree

10 files changed

+199
-140
lines changed

10 files changed

+199
-140
lines changed

CONTRIBUTING.md

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
# Contributing to Mindsdb
22

3-
We love to receive contributions from the community and hear your opinions! We want to make contributing to Mindsdb as easily as it can be.
3+
Being part of the core MindsDB team is accessible to anyone who is motivated and wants to be part of that journey!
44

5-
# How can you help us?
5+
Please see below how to contribute to the project, also refer to the contributing documentation.
6+
7+
## How can you help us?
68

79
* Report a bug
810
* Improve documentation
@@ -11,9 +13,9 @@ We love to receive contributions from the community and hear your opinions! We w
1113
* Propose new features
1214
* Test Mindsdb
1315

14-
# Code contributions
15-
In general, we follow the "fork-and-pull" Git workflow.
16+
## Code contributions
1617

18+
In general, we follow the "fork-and-pull" Git workflow.
1719
1. Fork the Mindsdb repository
1820
2. Clone the repository
1921
3. Make changes and commit them
@@ -22,14 +24,24 @@ In general, we follow the "fork-and-pull" Git workflow.
2224
6. Write a commit message
2325
7. Make sure that the CI tests are GREEN
2426

25-
>NOTE: Be sure to merge the latest from "upstream" before making a pull request!
27+
> NOTE: Be sure to merge the latest from "upstream" before making a pull request! Also, make the PR to the staging branch.
28+
29+
## Feature and Bug reports
30+
We use GitHub issues to track bugs and features. Report them by opening a [new issue](https://github.com/mindsdb/mindsdb_python_sdk/issues/new/choose) and fill out all of the required inputs.
31+
32+
## Code review process
33+
34+
The Pull Request reviews are done on a regular basis. Please, make sure you respond to our feedback/questions.
35+
36+
## Community
37+
38+
If you have additional questions or you want to chat with the MindsDB core team, please join our [Slack community](https://mindsdb.com/joincommunity) or post at [Github Discussions](https://github.com/mindsdb/mindsdb_python_sdk/discussions).
39+
40+
To get updates on MindsDB’s latest announcements, releases, and events, sign up for our [Monthly Community Newsletter](https://mindsdb.com/newsletter/?utm_medium=community&utm_source=github&utm_campaign=mindsdb%20repo).
41+
42+
Join our mission of democratizing machine learning!
2643

27-
# Feature and Bug reports
28-
We use GitHub issues to track bugs and features. Report them by opening a [new issue](https://github.com/mindsdb/mindsdb/issues/new/choose) and fill out all of the required inputs.
44+
## Contributor Code of Conduct
2945

30-
# Code review process
31-
The Pull Request reviews are done on a regular basis.
32-
Please, make sure you respond to our feedback/questions.
46+
Please note that this project is released with a [Contributor Code of Conduct](https://github.com/mindsdb/mindsdb_python_sdk/blob/stable/CODE_OF_CONDUCT.md). By participating in this project, you agree to abide by its terms.
3347

34-
# Community
35-
If you have additional questions or you want to chat with MindsDB core team, you can join our community [![Discourse posts](https://img.shields.io/discourse/posts?server=https%3A%2F%2Fcommunity.mindsdb.com%2F)](https://community.mindsdb.com/). To get updates on MindsDB’s latest announcements, releases, and events, [sign up for our newsletter](https://mindsdb.us20.list-manage.com/subscribe/post?u=5174706490c4f461e54869879&id=242786942a).

README.md

Lines changed: 55 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,161 +1,129 @@
11
# Python MindsDB SDK
2-
It enables you to connect to a MindsDB server from python using HTTP API.
32

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+
57
```
68
pip install mindsdb_sdk
79
```
810

911
## Example
1012

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:
1416

15-
# Connect to local server
17+
#### Connect to a local MindsDB server
1618

19+
```python
20+
import mindsdb_sdk
1721
server = mindsdb_sdk.connect()
1822
server = mindsdb_sdk.connect('http://127.0.0.1:47334')
23+
```
1924

20-
# Connect to cloud server
25+
#### Connect to the MindsDB Cloud
2126

27+
```python
28+
import mindsdb_sdk
2229
server = mindsdb_sdk.connect(email='a@b.com', password='-')
2330
server = mindsdb_sdk.connect('https://cloud.mindsdb.com', login='a@b.com', password='-')
31+
```
2432

25-
# Connect to MindsDB Pro
33+
#### Connect to a MindsDB Pro server
2634

35+
```python
36+
import mindsdb_sdk
2737
server = mindsdb_sdk.connect('http://<YOUR_INSTANCE_IP>', login='a@b.com', password='-', is_managed=True)
28-
2938
```
3039

31-
Base usage:
32-
```python
40+
## Basic usage
3341

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
3546
databases = server.list_databases()
3647

37-
database = databases[0] # Database type object
48+
# Get a specific database
49+
database = databases[0] # Database type object
3850

39-
# sql query
51+
# Perform an SQL query
4052
query = database.query('select * from table1')
4153
print(query.fetch())
4254

43-
# create table
55+
# Create a table
4456
table = database.create_table('table2', query)
4557

46-
47-
# project
58+
# Get a project
4859
project = server.get_project('proj')
4960

50-
# sql query
61+
# Perform an SQL query within a project
5162
query = project.query('select * from database.table join model1')
5263

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)
5866

59-
# get view
67+
# Get a list of views
6068
views = project.list_views()
6169
view = views[0]
6270
df = view.fetch()
6371

64-
# get model
72+
# Get a list of models
6573
models = project.list_models()
6674
model = models[0]
6775

68-
# using model
76+
# Use a model for prediction
6977
result_df = model.predict(df)
7078
result_df = model.predict(query)
7179

72-
# create model
80+
# Create a model
81+
timeseries_options = {
82+
'order': 'date',
83+
'window': 5,
84+
'horizon': 1
85+
}
7386
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
7791
)
7892

7993
```
8094

81-
More examples in [Google colab notebook](
95+
You can find more examples in this [Google colab notebook](
8296
https://colab.research.google.com/drive/1QouwAR3saFb9ffthrIs1LSH5COzyQa11#scrollTo=k6IbwsKRPQCR
8397
)
8498

85-
## API documentation
86-
87-
Api documentation can be found in:
88-
https://mindsdb.github.io/mindsdb_python_sdk/
89-
99+
## API Documentation
90100

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:
92102

93-
Locally:
103+
### Generating API docs locally:
94104

95105
```commandline
96106
cd docs
97-
98107
pip install -r requirements.txt
99-
100108
make html
101109
```
102110

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.
105112

106113

114+
## Testing
107115

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:
111117

112118
```bash
113119
env PYTHONPATH=./ pytest
114120
```
115121

116-
## How to Connect From a Python File
122+
## Contributing
117123

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.
119125

120-
`server.py`
126+
## License
121127

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
159129

160-
To see a full example, checkout:
161-
`server.py`

docs/tests/server.py

Lines changed: 0 additions & 33 deletions
This file was deleted.

mindsdb_sdk/__about__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__title__ = 'mindsdb_sdk'
22
__package_name__ = 'mindsdb_sdk'
3-
__version__ = '1.0.4'
3+
__version__ = '1.0.5'
44
__description__ = "MindsDB Python SDK, provides an SDK to use a remote mindsdb instance"
55
__email__ = "jorge@mindsdb.com"
66
__author__ = 'MindsDB Inc'

mindsdb_sdk/connectors/rest_api.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
from functools import wraps
2+
import io
23

34
import requests
45
import pandas as pd
56

7+
from .. import __about__
68

79
def _try_relogin(fnc):
810
@wraps(fnc)
@@ -38,6 +40,8 @@ def __init__(self, url=None, login=None, password=None, is_managed=False):
3840
self.is_managed = is_managed
3941
self.session = requests.Session()
4042

43+
self.session.headers['User-Agent'] = f'python-sdk/{__about__.__version__}'
44+
4145
if login is not None:
4246
self.login()
4347

@@ -114,3 +118,25 @@ def objects_tree(self, item=''):
114118
_raise_for_status(r)
115119

116120
return pd.DataFrame(r.json())
121+
122+
@_try_relogin
123+
def upload_file(self, name: str, df: pd.DataFrame):
124+
125+
# convert to file
126+
fd = io.BytesIO()
127+
df.to_csv(fd)
128+
fd.seek(0)
129+
130+
url = self.url + f'/api/files/{name}'
131+
r = self.session.put(
132+
url,
133+
data={
134+
'source': name,
135+
'name': name,
136+
'source_type': 'file',
137+
},
138+
files={
139+
'file': fd,
140+
}
141+
)
142+
_raise_for_status(r)

0 commit comments

Comments
 (0)