semvec/pypi-packages huggingface dataset:
semoss 1.0.3
Utility package to connect to SEMOSS instances and query data
License: MIT

# **semoss**

*semoss* is a Python module for connecting to [SEMOSS](https://semoss.org/).

## Using this package you can:

 - Pull data from an existing insight using REST API.
 - Create Pandas DataFrame from responses generated by SEMOSS that have 'TASK_DATA' operation type.
 - Run pixel and get the json response.

## **Install**

    pip install semoss


## **Usage**

To interract with a semoss instance, import the `semoss_connector` and establish a session:


### Setup
```python
>>> from semoss.connection import semoss_connector

# create connection object by passing in the base url for api
>>> semoss_connection = semoss_connector('http://localhost:8080/Monolith')

# establish a session. This will prompt a username & password login. Alternatively, you can set 'SEMOSS_USERNAME' and 'SEMOSS_PASSWORD' in environement variables. 
>>> semoss_connection.establishSession() 
True
```

### Using REST API to pull data from an Insight
```python
# define the Project ID
>>> projectId = '30991037-1e73-49f5-99d3-f28210e6b95c'

# define the Insight ID
>>> inishgtId = '26b373b3-cd52-452c-a987-0adb8817bf73'

# define the SQL for the SEMOSS frame you want to query within the insight
>>> sql = 'select * FROM SEMOSS_FRAME123'

# if you dont provide one of the following, it will ask you to provide it via prompt
>>> diabetes_df = semoss_connection.importFrameFromSemossApi(project_id = projectId, insight_id = inishgtId, sql = sql)
>>> diabetes_df.head()
```
|    |   AGE |   PATIENT |   WEIGHT |
|---:|------:|----------:|---------:|
|  0 |    19 |      4823 |      119 |
|  1 |    19 |     17790 |      135 |
|  2 |    20 |      1041 |      159 |
|  3 |    20 |      2763 |      274 |
|  4 |    20 |      3750 |      161 |

### Create a Pandas DataFrame from Task Data

```python
# define a pixel command
>>> pixel = 'Database ( database = [ "995cf169-6b44-4a42-b75c-af12f9f45c36" ] ) | Select ( DIABETES__AGE , DIABETES__PATIENT , DIABETES__WEIGHT ) .as ( [ AGE , PATIENT , WEIGHT ] ) | Distinct ( false ) | Collect(-1)'

# use getDataFrameFromTaskData method with the pixel command to create a Pandas DataFrame
>>> df = semoss_connection.getDataFrameFromTaskData(industryPixel)
>>> df.head()
```
|    |   AGE |   PATIENT |   WEIGHT |
|---:|------:|----------:|---------:|
|  0 |    19 |      4823 |      119 |
|  1 |    19 |     17790 |      135 |
|  2 |    20 |      1041 |      159 |
|  3 |    20 |      2763 |      274 |
|  4 |    20 |      3750 |      161 |

### Get the JSON response of any pixel
```python
# run the pixel
>>> semoss_connection.runPixel('1+1')
{'insightID': '8b419eaf-df7d-4a7f-869e-8d7d59bbfde8',
 'sessionTimeRemaining': '7196',
 'pixelReturn': [{'pixelId': '3',
   'pixelExpression': '1 + 1 ;',
   'isMeta': False,
   'output': 2,
   'operationType': ['OPERATION']}]}
```

---
## Dev
Please email SEMOSS