Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -179,4 +179,8 @@ cython_debug/
./mantis_sdk/main.py
mantis_sdk/main.py
test.csv
./test.csv
./test.csv
main.py
./main.py
./venv
venv/
50 changes: 45 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,15 @@ The `MantisClient` object requires the parameter `cookie` to be passed in. This
***Note***: If you are using a local backend, you must run it with docker, or the space creation will NOT work. To do so, `cd docker` from the backend root, then `docker compose up -d --build`. After you run the build once, you can re-run it simply with `docker compose up`. If things dno't work, check the logs and make sure they are not empty.

```python
from client import MantisClient, SpacePrivacy, DataType, ReducerModels
from render_args import RenderArgs
from mantis_sdk.client import MantisClient, SpacePrivacy, DataType, ReducerModels
from mantis_sdk.render_args import RenderArgs
from mantis_sdk.config import ConfigurationManager
import pandas as pd

mantis = MantisClient("/api/proxy/", cookie)
# You need to provide your cookie and a space_id (can be dummy for creation)
cookie = "YOUR_COOKIE_HERE"

mantis = MantisClient("/api/proxy/", cookie=cookie, space_id="dummy")

# Create DF (Real data will need more points)
df = pd.DataFrame({
Expand All @@ -58,10 +62,11 @@ new_space_id = mantis.create_space("Stock data",
data=df,
data_types=data_types,
reducer=ReducerModels.UMAP,
privacy_level=SpacePrivacy.Private)["space_id"]
privacy_level=SpacePrivacy.PRIVATE)["space_id"]

# Open space
space = await mantis.open_space(space_id)
# Re-initialize client with the new space_id if needed, or just use the space object
space = await mantis.open_space(new_space_id)

# Interact with space
await space.select_points(100)
Expand Down Expand Up @@ -166,4 +171,39 @@ await space.run_code (code)
await space.close_panel ("bags")
await space.close_panel ("quicksheet")
await space.close_panel ("userlogs")
```

### Notebooks

You can create and manage notebooks within a space.

```python
# Create a notebook
nb = mantis.create_notebook(space_id, "My Analysis", "user_id")
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

In this example snippet, the space_id variable is used but it has not been defined within this context. To make the example runnable and clearer for users, you should use new_space_id, which is created in the "Quick Start" example earlier in the document.

Suggested change
nb = mantis.create_notebook(space_id, "My Analysis", "user_id")
nb = mantis.create_notebook(new_space_id, "My Analysis", "user_id")


# Add a cell
code = """
print("Hello from Mantis Notebook!")
"""
cell = nb.add_cell(code)

# Execute cell
outputs = cell.execute()
print(outputs)
```

### Configuration

You can configure the client using `ConfigurationManager`.

```python
from mantis_sdk.config import ConfigurationManager

config = ConfigurationManager()
config.update({
"timeout": 60000,
"render_args": RenderArgs(headless=True)
})

mantis = MantisClient("/api/proxy/", cookie=cookie, space_id=space_id, config=config)
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The space_id variable used here is not defined in the example. To improve clarity, you should either use new_space_id from the previous examples or a placeholder string like "YOUR_SPACE_ID_HERE".

Suggested change
mantis = MantisClient("/api/proxy/", cookie=cookie, space_id=space_id, config=config)
mantis = MantisClient("/api/proxy/", cookie=cookie, space_id=new_space_id, config=config)

```
97 changes: 59 additions & 38 deletions examples/demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,25 @@
"# Import main SDK\n",
"from mantis_sdk.client import MantisClient, SpacePrivacy, DataType, ReducerModels\n",
"from mantis_sdk.render_args import RenderArgs\n",
"from mantis_sdk.config import ConfigurationManager\n",
"\n",
"import nest_asyncio\n",
"import asyncio\n",
"import pandas as pd\n",
"nest_asyncio.apply()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Setup authentication\n",
"# You need to get your cookie from the browser (dev tools -> network -> request headers)\n",
"cookie = \"YOUR_COOKIE_HERE\"\n"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand All @@ -41,8 +53,10 @@
"metadata": {},
"outputs": [],
"source": [
"# Load Mantis Client\n",
"mantis = MantisClient(\"/api/proxy/\", render_args=RenderArgs(viewport={\"width\": 1920, \"height\": 1080}))"
"# Load Mantis Client with Config\n",
"config = ConfigurationManager()\n",
"config.update({\"render_args\": RenderArgs(viewport={\"width\": 1920, \"height\": 1080})})\n",
"mantis = MantisClient(\"/api/proxy/\", cookie=cookie, space_id=\"dummy\", config=config)"
]
},
{
Expand All @@ -68,7 +82,7 @@
"outputs": [],
"source": [
"# Load Mantis\n",
"mantis = MantisClient(\"/api/proxy/\")\n",
"mantis = MantisClient(\"/api/proxy/\", cookie=cookie, space_id=\"dummy\")\n",
"\n",
"# Set data path + types\n",
"data_path = \"./StockData.csv\"\n",
Expand All @@ -94,7 +108,7 @@
"outputs": [],
"source": [
"# Alternative you can create dataframes\n",
"mantis = MantisClient(\"/api/proxy/\")\n",
"mantis = MantisClient(\"/api/proxy/\", cookie=cookie, space_id=\"dummy\")\n",
"\n",
"# Create DF\n",
"df = pd.DataFrame({\n",
Expand Down Expand Up @@ -187,39 +201,6 @@
"imshow (await stock_data_space.capture ())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Run Code**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"code = \"\"\"\n",
"\n",
"computation = 6**4\n",
"print ('Hello from SDK, :P -> ' + str(computation))\n",
"\n",
"\"\"\"\n",
"\n",
"\n",
"await stock_data_space.run_code (code)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"imshow (await stock_data_space.capture ())"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -335,7 +316,7 @@
"metadata": {},
"outputs": [],
"source": [
"mantis = MantisClient(\"/api/proxy/\")"
"mantis = MantisClient(\"/api/proxy/\", cookie=cookie, space_id=\"dummy\")"
]
},
{
Expand Down Expand Up @@ -381,6 +362,46 @@
" print (\"Space:\", space_name)\n",
" imshow (await space.capture ())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"**Notebook Automation**"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a notebook in the space\n",
"# We need a valid space_id. Assuming 'new_space_id' from previous cells is valid.\n",
"if 'new_space_id' in locals():\n",
" client = MantisClient(\"/api/proxy/\", cookie=cookie, space_id=new_space_id)\n",
" nb = client.create_notebook(new_space_id, \"SDK Demo Notebook\", \"sdk_user\")\n",
" \n",
" # Add a cell\n",
" code = \"\"\"\n",
"import matplotlib.pyplot as plt\n",
"import numpy as np\n",
"\n",
"x = np.linspace(0, 10, 100)\n",
"y = np.sin(x)\n",
"\n",
"plt.plot(x, y)\n",
"plt.title('Sine Wave')\n",
"plt.show()\n",
" \"\"\"\n",
" cell = nb.add_cell(code)\n",
" \n",
" # Execute the cell\n",
" outputs = cell.execute()\n",
" print(\"Execution outputs:\", outputs)\n",
"else:\n",
" print(\"Please run the 'Create Space' cells first to generate a space ID.\")"
]
}
],
"metadata": {
Expand Down
Loading