Skip to content

Commit

Permalink
Merge pull request #87 from mindsdb/staging
Browse files Browse the repository at this point in the history
Release 2.1.0
  • Loading branch information
ea-rus authored Jan 15, 2024
2 parents 4c89228 + 67f1983 commit df9a9f1
Show file tree
Hide file tree
Showing 24 changed files with 454 additions and 182 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/add_to_pr_review.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
name: Add Pull Requests to PR review project

on:
pull_request:
types:
- opened

jobs:
add-to-project:
name: Add issue to project
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/mindsdb/projects/65
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
14 changes: 14 additions & 0 deletions .github/workflows/add_to_roadmap_project_v2.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Add issue to roadmap project
on:
issues:
types:
- opened
jobs:
add-to-project:
name: Add issue to roadmap project
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
with:
project-url: https://github.com/orgs/mindsdb/projects/53
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
27 changes: 3 additions & 24 deletions .github/workflows/mindsdb_python_sdk.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
name: MindsDB Native workflow
name: PR workflow

on:
push:
pull_request:
branches:
- stable
Expand Down Expand Up @@ -43,6 +42,8 @@ jobs:
needs: test
if: github.ref != 'refs/heads/stable'
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.8
Expand All @@ -65,25 +66,3 @@ jobs:
with:
pytest-coverage-path: ./pytest-coverage.txt
junitxml-path: ./pytest.xml

deploy:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/stable'
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
- name: Install dependencies
run: |
python -m pip install --upgrade pip==20.2.4
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist
twine upload dist/*
61 changes: 61 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Release

on:
push:
branches:
- stable

jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest]
python-version: [3.7,3.8,3.9]
steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip==22.0.4
pip install -r requirements.txt
pip install --no-cache-dir .
- name: Run tests
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
env PYTHONPATH=./ pytest tests/
fi
shell: bash
env:
CHECK_FOR_UPDATES: False
DATABASE_CREDENTIALS_STRINGIFIED_JSON: ${{ secrets.DATABASE_CREDENTIALS }}
CLOUD_TEST_EMAIL: ${{ secrets.CLOUD_TEST_EMAIL }}
CLOUD_TEST_PASSWORD: ${{ secrets.CLOUD_TEST_PASSWORD }}


deploy:
runs-on: ubuntu-latest
needs: test
if: github.ref == 'refs/heads/stable'
steps:
- uses: actions/checkout@v2
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: '3.7'
- name: Install dependencies
run: |
python -m pip install --upgrade pip==20.2.4
pip install setuptools wheel twine
- name: Build and publish
env:
TWINE_USERNAME: __token__
TWINE_PASSWORD: ${{ secrets.PYPI_PASSWORD }}
run: |
python setup.py sdist
twine upload dist/*
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ https://github.com/mindsdb/mindsdb_python_sdk/tree/staging/examples

## API Documentation

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:
The API documentation for the MindsDB SDK can be found at https://mindsdb.github.io/mindsdb_python_sdk/.

### Generating API docs locally:

Expand Down
6 changes: 5 additions & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,11 @@
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.napoleon']
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.autosectionlabel'
]

templates_path = ['_templates']
exclude_patterns = []
Expand Down
7 changes: 4 additions & 3 deletions docs/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Base usage
More
More examples
-----------
-------------

`<https://github.com/mindsdb/mindsdb_python_sdk/examples>`_

Expand All @@ -107,12 +107,13 @@ API documentation
:maxdepth: 1
:caption: Modules:


server
database

project
handlers

ml_engines
project
model
tables
views
Expand Down
3 changes: 3 additions & 0 deletions docs/source/jobs.rst
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Jobs
-------------------------

.. _my-reference-label:


.. automodule:: mindsdb_sdk.jobs
:members:
:undoc-members:
Expand Down
5 changes: 4 additions & 1 deletion docs/source/server.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,7 @@ Server
.. automodule:: mindsdb_sdk.server
:members:
:undoc-members:
:show-inheritance:
:show-inheritance:


:ref:`jobs<Jobs>`
45 changes: 34 additions & 11 deletions examples/working_with_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,44 @@

con = mindsdb_sdk.connect()

# get user's database (connected to mindsdb as rental_db)
db = con.databases.rental_db
# connect to mindsdb example database
example_db = con.databases.create(
'example_db',
engine='postgres',
connection_args={
"user": "demo_user",
"password": "demo_password",
"host": "3.220.66.106",
"port": "5432",
"database": "demo"
}
)

# get table
table1 = db.tables.house_sales
# connect to the empty user database
my_db = con.databases.create(
'my_db',
engine='postgres',
connection_args={
"user": "postgres",
"host": "localhost",
"port": "5432",
"database": "my_database"
}
)

# get home_rentals table
table1 = example_db.tables.get('demo_data.home_rentals')

# ---- create new table ----

# copy create table house_sales and fill it with rows with type=house
table2 = db.tables.create('house_sales2', table1.filter(type='house'))
# create table home_rentals in user db and fill it with rows with location=great
table2 = my_db.tables.create('home_rentals', table1.filter(location='great'))


# create table from csv file

df = pd.read_csv('my_data.csv')
table3 = db.tables.create('my_table', df)
table3 = my_db.tables.create('my_table', df)


# ---- insert into table ----
Expand All @@ -28,16 +51,16 @@

# ---- update data in table ----

# get all rows with type=house from table1 and update values in table2 using key ('saledate', 'type', 'bedrooms')
# get all rows with number_of_rooms=1 from table1 and update values in table2 using key ('location', 'neighborhood')
table2.update(
table1.filter(type='house'),
on=['saledate', 'type', 'bedrooms']
table1.filter(number_of_rooms=1),
on=['location', 'neighborhood']
)


# ---- delete rows from table ----

# delete all rows where bedrooms=2
table2.delete(bedrooms=2)
table2.delete(number_of_rooms=1)


2 changes: 1 addition & 1 deletion mindsdb_sdk/__about__.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
__title__ = 'mindsdb_sdk'
__package_name__ = 'mindsdb_sdk'
__version__ = '2.0.0'
__version__ = '2.1.0'
__description__ = "MindsDB Python SDK, provides an SDK to use a remote mindsdb instance"
__email__ = "[email protected]"
__author__ = 'MindsDB Inc'
Expand Down
10 changes: 5 additions & 5 deletions mindsdb_sdk/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,17 @@ def connect(url: str = None, login: str = None, password: str = None, is_managed
Connect to local server
>>> server = mindsdb_sdk.connect()
>>> server = mindsdb_sdk.connect('http://127.0.0.1:47334')
>>> con = mindsdb_sdk.connect()
>>> con = mindsdb_sdk.connect('http://127.0.0.1:47334')
Connect to cloud server
>>> server = mindsdb_sdk.connect(login='[email protected]', password='-')
>>> server = mindsdb_sdk.connect('https://cloud.mindsdb.com', login='[email protected]', password='-')
>>> con = mindsdb_sdk.connect(login='[email protected]', password='-')
>>> con = mindsdb_sdk.connect('https://cloud.mindsdb.com', login='[email protected]', password='-')
Connect to MindsDB pro
>>> server = mindsdb_sdk.connect('http://<YOUR_INSTANCE_IP>', login='[email protected]', password='-', is_managed=True)
>>> con = mindsdb_sdk.connect('http://<YOUR_INSTANCE_IP>', login='[email protected]', password='-', is_managed=True)
"""
if url is None:
Expand Down
24 changes: 22 additions & 2 deletions mindsdb_sdk/connectors/rest_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def upload_file(self, name: str, df: pd.DataFrame):

# convert to file
fd = io.BytesIO()
df.to_csv(fd)
df.to_csv(fd, index=False)
fd.seek(0)

url = self.url + f'/api/files/{name}'
Expand All @@ -139,4 +139,24 @@ def upload_file(self, name: str, df: pd.DataFrame):
'file': fd,
}
)
_raise_for_status(r)
_raise_for_status(r)

@_try_relogin
def upload_byom(self, name: str, code: str, requirements: str):

url = self.url + f'/api/handlers/byom/{name}'
r = self.session.put(
url,
files={
'code': code,
'modules': requirements,
}
)
_raise_for_status(r)

def status(self) -> dict:

r = self.session.get(self.url + f'/api/status')
_raise_for_status(r)

return r.json()
8 changes: 6 additions & 2 deletions mindsdb_sdk/databases.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from typing import List
from typing import List, Union

from mindsdb_sql.parser.dialects.mindsdb import CreateDatabase
from mindsdb_sql.parser.ast import DropDatabase, Identifier
Expand All @@ -7,6 +7,7 @@

from .query import Query
from .tables import Tables
from .handlers import Handler


class Database:
Expand Down Expand Up @@ -93,7 +94,7 @@ def list(self) -> List[Database]:
"""
return [Database(self, name) for name in self._list_databases()]

def create(self, name: str, engine: str, connection_args: dict) -> Database:
def create(self, name: str, engine: Union[str, Handler], connection_args: dict) -> Database:
"""
Create new integration and return it
Expand All @@ -102,6 +103,9 @@ def create(self, name: str, engine: str, connection_args: dict) -> Database:
:param connection_args: {"key": "value"} object with the connection parameters specific for each engine
:return: created Database object
"""
if isinstance(engine, Handler):
engine = engine.name

ast_query = CreateDatabase(
name=Identifier(name),
engine=engine,
Expand Down
Loading

0 comments on commit df9a9f1

Please sign in to comment.