Skip to content

Commit dd95939

Browse files
authored
Merge pull request #64 from ydb-platform/update_example_notebook
update notebook example
2 parents d35417b + 89bba30 commit dd95939

File tree

1 file changed

+30
-133
lines changed

1 file changed

+30
-133
lines changed

examples/jupyter_notebook/YDB SQLAlchemy + Jupyter Notebook Example.ipynb

+30-133
Original file line numberDiff line numberDiff line change
@@ -37,48 +37,25 @@
3737
{
3838
"cell_type": "code",
3939
"execution_count": 1,
40+
"id": "2d200ccc-c125-4064-897f-4b8d325d23b7",
41+
"metadata": {},
42+
"outputs": [],
43+
"source": [
44+
"import warnings\n",
45+
"warnings.filterwarnings('ignore')\n",
46+
"warnings.simplefilter('ignore')"
47+
]
48+
},
49+
{
50+
"cell_type": "code",
51+
"execution_count": null,
4052
"id": "1bac5cad-31e1-4dcb-a8c9-5cac24899220",
4153
"metadata": {
4254
"scrolled": true
4355
},
44-
"outputs": [
45-
{
46-
"name": "stdout",
47-
"output_type": "stream",
48-
"text": [
49-
"\n",
50-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
51-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
52-
"Note: you may need to restart the kernel to use updated packages.\n"
53-
]
54-
},
55-
{
56-
"name": "stderr",
57-
"output_type": "stream",
58-
"text": [
59-
"/Users/ovcharuk/work/ydb-python-examples/.venv/lib/python3.9/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
60-
" from .autonotebook import tqdm as notebook_tqdm\n"
61-
]
62-
},
63-
{
64-
"name": "stdout",
65-
"output_type": "stream",
66-
"text": [
67-
"Warning: Looks like you're using an outdated `kagglehub` version, please consider updating (latest version: 0.3.4)\n"
68-
]
69-
},
70-
{
71-
"data": {
72-
"text/plain": [
73-
"'/Users/ovcharuk/.cache/kagglehub/datasets/hosammhmdali/mall-customers-dataset/versions/1/Mall_Customers.csv'"
74-
]
75-
},
76-
"execution_count": 1,
77-
"metadata": {},
78-
"output_type": "execute_result"
79-
}
80-
],
56+
"outputs": [],
8157
"source": [
58+
"%pip install --upgrade pip --quiet\n",
8259
"%pip install kagglehub --quiet\n",
8360
"\n",
8461
"import kagglehub\n",
@@ -90,8 +67,7 @@
9067
"# Retrieve csv file path\n",
9168
"dataset_dir = os.listdir(path)\n",
9269
"dataset_name = [name for name in dataset_dir if name.endswith(\".csv\")]\n",
93-
"dataset_path = f\"{path}/{dataset_name[0]}\"\n",
94-
"dataset_path"
70+
"dataset_path = f\"{path}/{dataset_name[0]}\""
9571
]
9672
},
9773
{
@@ -104,17 +80,14 @@
10480
},
10581
{
10682
"cell_type": "code",
107-
"execution_count": 2,
83+
"execution_count": 3,
10884
"id": "380c7989-236f-4714-bf0e-c8d13aa029c0",
10985
"metadata": {},
11086
"outputs": [
11187
{
11288
"name": "stdout",
11389
"output_type": "stream",
11490
"text": [
115-
"\n",
116-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
117-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
11891
"Note: you may need to restart the kernel to use updated packages.\n"
11992
]
12093
},
@@ -200,7 +173,7 @@
200173
"4 5 Female 31 17 40"
201174
]
202175
},
203-
"execution_count": 2,
176+
"execution_count": 3,
204177
"metadata": {},
205178
"output_type": "execute_result"
206179
}
@@ -230,7 +203,7 @@
230203
},
231204
{
232205
"cell_type": "code",
233-
"execution_count": 3,
206+
"execution_count": 4,
234207
"id": "ab8bdc54-9c7a-44b7-84ad-fd39d550799c",
235208
"metadata": {
236209
"scrolled": true
@@ -318,7 +291,7 @@
318291
"4 5 Female 31 17 40"
319292
]
320293
},
321-
"execution_count": 3,
294+
"execution_count": 4,
322295
"metadata": {},
323296
"output_type": "execute_result"
324297
}
@@ -368,21 +341,10 @@
368341
},
369342
{
370343
"cell_type": "code",
371-
"execution_count": 4,
344+
"execution_count": null,
372345
"id": "224d8411-f2b1-4983-b36f-370a43283f14",
373346
"metadata": {},
374-
"outputs": [
375-
{
376-
"name": "stdout",
377-
"output_type": "stream",
378-
"text": [
379-
"\n",
380-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
381-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
382-
"Note: you may need to restart the kernel to use updated packages.\n"
383-
]
384-
}
385-
],
347+
"outputs": [],
386348
"source": [
387349
"%pip install ydb-sqlalchemy==0.1.3 --quiet"
388350
]
@@ -397,32 +359,6 @@
397359
"Skip this part if your YDB installation uses another auth method."
398360
]
399361
},
400-
{
401-
"cell_type": "code",
402-
"execution_count": 5,
403-
"id": "aaa82a4f-adbd-4116-bf77-dec14b5b0d9f",
404-
"metadata": {},
405-
"outputs": [
406-
{
407-
"name": "stdout",
408-
"output_type": "stream",
409-
"text": [
410-
"\n",
411-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
412-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
413-
"Note: you may need to restart the kernel to use updated packages.\n"
414-
]
415-
}
416-
],
417-
"source": [
418-
"%pip install yandexcloud --quiet\n",
419-
"\n",
420-
"import json\n",
421-
"sa_json_file_path = \"/Users/ovcharuk/authorized_key.json\"\n",
422-
"with open(sa_json_file_path, 'r') as f:\n",
423-
" sa_json = json.load(f)"
424-
]
425-
},
426362
{
427363
"cell_type": "markdown",
428364
"id": "e453c5e4-6c6f-414e-b87c-c9e06bd20a19",
@@ -442,17 +378,7 @@
442378
"source": [
443379
"import sqlalchemy as sa\n",
444380
"\n",
445-
"args = {\n",
446-
" \"_add_declare_for_yql_stmt_vars\": True,\n",
447-
" \"connect_args\": {\n",
448-
" \"protocol\": \"grpcs\",\n",
449-
" \"credentials\": {\n",
450-
" \"service_account_json\": sa_json\n",
451-
" }\n",
452-
" }\n",
453-
"}\n",
454-
"\n",
455-
"engine = sa.create_engine(\"yql+ydb://ydb.serverless.yandexcloud.net:2135//ru-central1/b1g8skpblkos03malf3s/etnkr25d1qgm50un6sl1\", **args)\n",
381+
"engine = sa.create_engine(\"yql+ydb://localhost:2136/local\")\n",
456382
"conn = engine.connect()"
457383
]
458384
},
@@ -489,7 +415,7 @@
489415
{
490416
"data": {
491417
"text/plain": [
492-
"<sqlalchemy.engine.cursor.CursorResult at 0x12001d340>"
418+
"<sqlalchemy.engine.cursor.CursorResult at 0x10b035600>"
493419
]
494420
},
495421
"execution_count": 7,
@@ -910,21 +836,10 @@
910836
"id": "a7842a2e-247b-4750-9ba1-af1784ccb3ab",
911837
"metadata": {},
912838
"outputs": [
913-
{
914-
"name": "stderr",
915-
"output_type": "stream",
916-
"text": [
917-
"WARNING: All log messages before absl::InitializeLog() is called are written to STDERR\n",
918-
"I0000 00:00:1732871554.047402 1744191 fork_posix.cc:75] Other threads are currently calling into gRPC, skipping fork() handlers\n"
919-
]
920-
},
921839
{
922840
"name": "stdout",
923841
"output_type": "stream",
924842
"text": [
925-
"\n",
926-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
927-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
928843
"Note: you may need to restart the kernel to use updated packages.\n"
929844
]
930845
},
@@ -974,28 +889,10 @@
974889
},
975890
{
976891
"cell_type": "code",
977-
"execution_count": 12,
892+
"execution_count": null,
978893
"id": "0ecaaf12-4906-4cc3-a3de-6f59102a439f",
979894
"metadata": {},
980-
"outputs": [
981-
{
982-
"name": "stderr",
983-
"output_type": "stream",
984-
"text": [
985-
"I0000 00:00:1732871555.087487 1744191 fork_posix.cc:75] Other threads are currently calling into gRPC, skipping fork() handlers\n"
986-
]
987-
},
988-
{
989-
"name": "stdout",
990-
"output_type": "stream",
991-
"text": [
992-
"\n",
993-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m A new release of pip is available: \u001b[0m\u001b[31;49m24.1.2\u001b[0m\u001b[39;49m -> \u001b[0m\u001b[32;49m24.3.1\u001b[0m\n",
994-
"\u001b[1m[\u001b[0m\u001b[34;49mnotice\u001b[0m\u001b[1;39;49m]\u001b[0m\u001b[39;49m To update, run: \u001b[0m\u001b[32;49mpip install --upgrade pip\u001b[0m\n",
995-
"Note: you may need to restart the kernel to use updated packages.\n"
996-
]
997-
}
998-
],
895+
"outputs": [],
999896
"source": [
1000897
"%pip install jupysql --quiet\n",
1001898
"%load_ext sql"
@@ -1036,10 +933,10 @@
1036933
{
1037934
"data": {
1038935
"text/html": [
1039-
"<span style=\"None\">Running query in &#x27;yql+ydb://ydb.serverless.yandexcloud.net:2135//ru-central1/b1g8skpblkos03malf3s/etnkr25d1qgm50un6sl1&#x27;</span>"
936+
"<span style=\"None\">Running query in &#x27;yql+ydb://localhost:2136/local&#x27;</span>"
1040937
],
1041938
"text/plain": [
1042-
"Running query in 'yql+ydb://ydb.serverless.yandexcloud.net:2135//ru-central1/b1g8skpblkos03malf3s/etnkr25d1qgm50un6sl1'"
939+
"Running query in 'yql+ydb://localhost:2136/local'"
1043940
]
1044941
},
1045942
"metadata": {},
@@ -1181,10 +1078,10 @@
11811078
{
11821079
"data": {
11831080
"text/html": [
1184-
"<span style=\"None\">Running query in &#x27;yql+ydb://ydb.serverless.yandexcloud.net:2135//ru-central1/b1g8skpblkos03malf3s/etnkr25d1qgm50un6sl1&#x27;</span>"
1081+
"<span style=\"None\">Running query in &#x27;yql+ydb://localhost:2136/local&#x27;</span>"
11851082
],
11861083
"text/plain": [
1187-
"Running query in 'yql+ydb://ydb.serverless.yandexcloud.net:2135//ru-central1/b1g8skpblkos03malf3s/etnkr25d1qgm50un6sl1'"
1084+
"Running query in 'yql+ydb://localhost:2136/local'"
11881085
]
11891086
},
11901087
"metadata": {},
@@ -1255,7 +1152,7 @@
12551152
"name": "python",
12561153
"nbconvert_exporter": "python",
12571154
"pygments_lexer": "ipython3",
1258-
"version": "3.9.19"
1155+
"version": "3.10.15"
12591156
}
12601157
},
12611158
"nbformat": 4,

0 commit comments

Comments
 (0)