Skip to content

Commit

Permalink
Revert "add(notebook): remove metadata from code cells" (#123)
Browse files Browse the repository at this point in the history
This reverts commit 246cbef.
  • Loading branch information
mivasconcelos authored Nov 14, 2024
1 parent 69c6699 commit c6dc81c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 7 deletions.
45 changes: 41 additions & 4 deletions notebooks/cloud-functions-template/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"cell_type": "markdown",
"id": "cd7deb95-c7bb-48eb-9cab-ed508b3be5ff",
"id": "e0f88a6f-2658-40b4-9356-935a09f5053e",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
Expand All @@ -34,6 +34,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "a5564913-7ff8-41bf-b64b-b67971c63fae",
"metadata": {},
"source": [
"This Jupyter notebook will help you build your first Cloud Function, showcasing how to leverage the ultra-fast queries of SingleStore to build a responsive API server using FastAPI"
]
Expand All @@ -42,6 +43,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "1e394195-29b4-403c-9abf-5d7731349eb6",
"metadata": {},
"source": [
"## Create some simple tables\n",
"\n",
Expand All @@ -52,6 +54,7 @@
"cell_type": "code",
"execution_count": 1,
"id": "a17bdd3a-16b3-4e19-8a56-6566a169eccb",
"metadata": {},
"outputs": [],
"source": [
"%%sql\n",
Expand All @@ -69,6 +72,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "af6e2618-de97-4397-b0d2-23e4a4df1d83",
"metadata": {},
"source": [
"## Create a Connection Pool\n",
"\n",
Expand All @@ -79,6 +83,7 @@
"cell_type": "code",
"execution_count": 2,
"id": "f485e71b-2b05-4696-b22a-cf046fd83090",
"metadata": {},
"outputs": [],
"source": [
"from sqlalchemy import create_engine, text\n",
Expand All @@ -91,8 +96,9 @@
"with open(ca_cert_path, \"wb\") as f:\n",
" f.write(response.content)\n",
"\n",
"sql_connection_string = connection_url.replace(\"singlestoredb\", \"mysql+pymysql\")\n",
"engine = create_engine(\n",
" f\"{connection_url}?ssl_ca={ca_cert_path}\",\n",
" f\"{sql_connection_string}?ssl_ca={ca_cert_path}\",\n",
" pool_size=10, # Maximum number of connections in the pool is 10\n",
" max_overflow=5, # Allow up to 5 additional connections (temporary overflow)\n",
" pool_timeout=30 # Wait up to 30 seconds for a connection from the pool\n",
Expand All @@ -118,6 +124,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "ee9058a9-34a5-46fc-8b12-d30cbb8c3340",
"metadata": {},
"source": [
"## Setup Environment\n",
"\n",
Expand All @@ -128,6 +135,7 @@
"cell_type": "code",
"execution_count": 3,
"id": "66df8f0c-70c6-4f06-9e64-ef06961cca3a",
"metadata": {},
"outputs": [],
"source": [
"from fastapi import FastAPI, HTTPException\n",
Expand All @@ -153,6 +161,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "96760949-5ab2-474d-80ca-d23b5dcc52f7",
"metadata": {},
"source": [
"## Define FastAPI App\n",
"\n",
Expand All @@ -163,6 +172,7 @@
"cell_type": "code",
"execution_count": 4,
"id": "3087dbe6-57ce-4410-a42f-5b0fe90add90",
"metadata": {},
"outputs": [],
"source": [
"app = FastAPI()\n",
Expand All @@ -178,7 +188,6 @@
" try:\n",
" return await run_in_thread(get_items_query)\n",
" except Exception as e:\n",
"\n",
" raise HTTPException(status_code=500, detail=f\"Error fetching all items: {str(e)}\")\n",
"\n",
"# Insert an item\n",
Expand Down Expand Up @@ -227,6 +236,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "c3d9ed07-4b55-4d17-aabb-e11b399109d1",
"metadata": {},
"source": [
"## Start the FastAPI server\n",
"\n",
Expand All @@ -237,6 +247,7 @@
"cell_type": "code",
"execution_count": 5,
"id": "ff002c7d-9f1c-40e5-b82a-c9176251dc99",
"metadata": {},
"outputs": [],
"source": [
"import singlestoredb.apps as apps\n",
Expand All @@ -247,6 +258,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "fabe76b7-e6a0-43a0-8d9e-aa79bd7d3021",
"metadata": {},
"source": [
"## Publish Cloud Function\n",
"\n",
Expand All @@ -255,14 +267,39 @@
},
{
"cell_type": "markdown",
"id": "386f804b-f3a9-4452-9575-b87c917bbbf8",
"id": "55513fb9-f288-4cf1-b371-a71439bb1a31",
"metadata": {},
"source": [
"<div id=\"singlestore-footer\" style=\"background-color: rgba(194, 193, 199, 0.25); height:2px; margin-bottom:10px\"></div>\n",
"<div><img src=\"https://raw.githubusercontent.com/singlestore-labs/spaces-notebooks/master/common/images/singlestore-logo-grey.png\" style=\"padding: 0px; margin: 0px; height: 24px\"/></div>"
]
}
],
"metadata": {
"jupyterlab": {
"notebooks": {
"version_major": 6,
"version_minor": 4
}
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
47 changes: 44 additions & 3 deletions notebooks/create-dash-app/notebook.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
},
{
"cell_type": "markdown",
"id": "1d98a67c-972c-43fd-8947-e251dc1b5b96",
"id": "c5893325-17c9-495f-862f-049072c30806",
"metadata": {},
"source": [
"<div class=\"alert alert-block alert-warning\">\n",
Expand All @@ -34,6 +34,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "df860ca4-6db8-4ded-a061-30be438c4add",
"metadata": {},
"source": [
"This Jupyter notebook will help you build your first real time Dashboard, showcasing how to leverage the ultra-fast queries of SingleStore to build a great visual experience using Plotly's DashApps."
]
Expand All @@ -53,6 +54,7 @@
"cell_type": "code",
"execution_count": 1,
"id": "d218d020-b9dc-4419-961d-2232ca0893f8",
"metadata": {},
"outputs": [],
"source": [
"%%sql\n",
Expand All @@ -70,6 +72,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "c6e492c6-74c8-488f-a456-fae59af0c69d",
"metadata": {},
"source": [
"## Insert some data\n",
"\n",
Expand All @@ -80,6 +83,7 @@
"cell_type": "code",
"execution_count": 2,
"id": "98e60d97-42ce-4600-8e35-556c70f9d4c2",
"metadata": {},
"outputs": [],
"source": [
"%%sql\n",
Expand Down Expand Up @@ -111,6 +115,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "beb57814-ad38-4065-a730-59576f6a72e3",
"metadata": {},
"source": [
"## Create a Connection Pool\n",
"\n",
Expand All @@ -121,6 +126,7 @@
"cell_type": "code",
"execution_count": 3,
"id": "f030ce86-4940-4014-8227-6b8c9cb56246",
"metadata": {},
"outputs": [],
"source": [
"from sqlalchemy import create_engine, text\n",
Expand All @@ -133,8 +139,9 @@
"with open(ca_cert_path, \"wb\") as f:\n",
" f.write(response.content)\n",
"\n",
"sql_connection_string = connection_url.replace(\"singlestoredb\", \"mysql+pymysql\")\n",
"engine = create_engine(\n",
" f\"{connection_url}?ssl_ca={ca_cert_path}\",\n",
" f\"{sql_connection_string}?ssl_ca={ca_cert_path}\",\n",
" pool_size=10, # Maximum number of connections in the pool is 10\n",
" max_overflow=5, # Allow up to 5 additional connections (temporary overflow)\n",
" pool_timeout=30 # Wait up to 30 seconds for a connection from the pool\n",
Expand All @@ -149,6 +156,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "dd87d196-3d52-4f3a-8dd4-d5f3540b051f",
"metadata": {},
"source": [
"## Create a line chart\n",
"\n",
Expand All @@ -161,6 +169,7 @@
"cell_type": "code",
"execution_count": 4,
"id": "712cd20d-6f2d-4c5a-9094-11b611ce622d",
"metadata": {},
"outputs": [],
"source": [
"import pandas as pd\n",
Expand Down Expand Up @@ -192,6 +201,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "cc363aa0-a8d5-4f7e-bdae-5a22d56e0bcf",
"metadata": {},
"source": [
"## Create a pie chart\n",
"\n",
Expand All @@ -202,6 +212,7 @@
"cell_type": "code",
"execution_count": 5,
"id": "79aa80ef-4a49-4238-87fb-f90a16ba4e42",
"metadata": {},
"outputs": [],
"source": [
"def generate_pie_chart(date):\n",
Expand All @@ -222,6 +233,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "94586a2e-76b2-48f8-8dbd-ff7038443ae1",
"metadata": {},
"source": [
"## Define the Dash App Layout and Callbacks\n",
"\n",
Expand All @@ -233,6 +245,7 @@
"cell_type": "code",
"execution_count": 6,
"id": "de733262-834b-48b6-b885-78dfc5ebb452",
"metadata": {},
"outputs": [],
"source": [
"from singlestoredb import apps\n",
Expand Down Expand Up @@ -308,6 +321,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "f287e202-704b-4eb5-8290-fb08ba9a493c",
"metadata": {},
"source": [
"## Start the Dash App server\n",
"\n",
Expand All @@ -318,6 +332,7 @@
"cell_type": "code",
"execution_count": 7,
"id": "69632c1b-f981-4338-9f91-ca8ae746cd73",
"metadata": {},
"outputs": [],
"source": [
"connectionInfo = await apps.run_dashboard_app(app)"
Expand All @@ -327,6 +342,7 @@
"attachments": {},
"cell_type": "markdown",
"id": "4fe4abd0-d52f-475a-89a4-d518f2b37d0d",
"metadata": {},
"source": [
"## Publish Dashboard\n",
"\n",
Expand All @@ -335,14 +351,39 @@
},
{
"cell_type": "markdown",
"id": "5da7ba27-6006-48c2-92a5-ea2bd2e609a3",
"id": "8eb7fab3-c714-4b3b-93a7-ce8a9836ded2",
"metadata": {},
"source": [
"<div id=\"singlestore-footer\" style=\"background-color: rgba(194, 193, 199, 0.25); height:2px; margin-bottom:10px\"></div>\n",
"<div><img src=\"https://raw.githubusercontent.com/singlestore-labs/spaces-notebooks/master/common/images/singlestore-logo-grey.png\" style=\"padding: 0px; margin: 0px; height: 24px\"/></div>"
]
}
],
"metadata": {
"jupyterlab": {
"notebooks": {
"version_major": 6,
"version_minor": 4
}
},
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit c6dc81c

Please sign in to comment.