Skip to content

Commit 4fa34b6

Browse files
authored
Merge pull request #30 from csaranbalaji/master
Fixed bike tutorial db connection issue
2 parents a99fdc8 + 08a885d commit 4fa34b6

File tree

1 file changed

+275
-34
lines changed

1 file changed

+275
-34
lines changed

bike-tutorial/python/Create TerminusDB Graph with Python Client.ipynb

Lines changed: 275 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -2,37 +2,112 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": null,
5+
"execution_count": 1,
66
"metadata": {},
77
"outputs": [],
88
"source": [
9-
"import terminusdb_client as woql\n",
10-
"from terminusdb_client import woqldataframe\n",
119
"from terminusdb_client import WOQLQuery\n",
10+
"from terminusdb_client import WOQLClient\n",
11+
"from terminusdb_client import woqldataframe\n",
1212
"\n",
13-
"server_url = \"http://localhost:6363\"\n",
14-
"account_id = \"admin\"\n",
15-
"user_id=\"admin\"\n",
13+
"server_url = \"https://127.0.0.1:6363\"\n",
14+
"user = \"admin\"\n",
15+
"account = \"admin\"\n",
1616
"key = \"root\"\n",
17-
"db_id = \"pybike\"\n",
18-
"db_name = \"Bicycle Graph\"\n",
19-
"\n",
20-
"\n",
21-
"client = woql.WOQLClient(server_url=\"http://localhost:6363\")\n",
22-
"client.connect(key=key, account=account_id, user=user_id)\n",
17+
"dbid = \"pybike\"\n",
18+
"repository = \"local\"\n",
19+
"label = \"Bike Graph\"\n",
20+
"description = \"Create a graph with bike data\"\n",
2321
"\n",
24-
"existing = client.get_metadata(db_id, client.uid())\n",
25-
"if not existing:\n",
26-
" client.create_database(db_id, accountid=\"admin\", label = \"Bike Graph\", description = \"Create a graph with bike data\")\n",
27-
"else:\n",
28-
" client.db(db_id)\n"
22+
"client = WOQLClient(server_url)\n",
23+
"result = client.connect(user=user,account=account,key=key,db=dbid)"
2924
]
3025
},
3126
{
3227
"cell_type": "code",
33-
"execution_count": null,
28+
"execution_count": 2,
3429
"metadata": {},
35-
"outputs": [],
30+
"outputs": [
31+
{
32+
"name": "stderr",
33+
"output_type": "stream",
34+
"text": [
35+
"/Users/saran-7185/personal_repos/pycon-devsprint2020/terminusdb/terminusdb-bootstrap/env/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
36+
" and should_run_async(code)\n"
37+
]
38+
},
39+
{
40+
"data": {
41+
"text/plain": [
42+
"{'@type': 'api:DbDeleteResponse', 'api:status': 'api:success'}"
43+
]
44+
},
45+
"execution_count": 2,
46+
"metadata": {},
47+
"output_type": "execute_result"
48+
}
49+
],
50+
"source": [
51+
"# Uncomment this to delete your old database first\n",
52+
"# client.delete_database(dbid)"
53+
]
54+
},
55+
{
56+
"cell_type": "code",
57+
"execution_count": 3,
58+
"metadata": {},
59+
"outputs": [
60+
{
61+
"name": "stderr",
62+
"output_type": "stream",
63+
"text": [
64+
"/Users/saran-7185/personal_repos/pycon-devsprint2020/terminusdb/terminusdb-bootstrap/env/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
65+
" and should_run_async(code)\n"
66+
]
67+
}
68+
],
69+
"source": [
70+
"# Create the database\n",
71+
"try:\n",
72+
" client.create_database(dbid,user,label=label, description=description)\n",
73+
"except Exception as E:\n",
74+
" error_obj = E.errorObj\n",
75+
" if \"api:DatabaseAlreadyExists\" == error_obj.get(\"api:error\",{}).get(\"@type\",None):\n",
76+
" print(f'Warning: Database \"{dbid}\" already exists!\\n')\n",
77+
" else:\n",
78+
" raise(E)"
79+
]
80+
},
81+
{
82+
"cell_type": "code",
83+
"execution_count": 4,
84+
"metadata": {},
85+
"outputs": [
86+
{
87+
"name": "stderr",
88+
"output_type": "stream",
89+
"text": [
90+
"/Users/saran-7185/personal_repos/pycon-devsprint2020/terminusdb/terminusdb-bootstrap/env/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
91+
" and should_run_async(code)\n"
92+
]
93+
},
94+
{
95+
"data": {
96+
"text/plain": [
97+
"{'@type': 'api:WoqlResponse',\n",
98+
" 'api:status': 'api:success',\n",
99+
" 'api:variable_names': [],\n",
100+
" 'bindings': [{}],\n",
101+
" 'deletes': 0,\n",
102+
" 'inserts': 34,\n",
103+
" 'transaction_retry_count': 0}"
104+
]
105+
},
106+
"execution_count": 4,
107+
"metadata": {},
108+
"output_type": "execute_result"
109+
}
110+
],
36111
"source": [
37112
"def create_schema(client, commit_msg):\n",
38113
" \"\"\"The query which creates the schema\n",
@@ -61,9 +136,18 @@
61136
},
62137
{
63138
"cell_type": "code",
64-
"execution_count": null,
139+
"execution_count": 5,
65140
"metadata": {},
66-
"outputs": [],
141+
"outputs": [
142+
{
143+
"name": "stderr",
144+
"output_type": "stream",
145+
"text": [
146+
"/Users/saran-7185/personal_repos/pycon-devsprint2020/terminusdb/terminusdb-bootstrap/env/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
147+
" and should_run_async(code)\n"
148+
]
149+
}
150+
],
67151
"source": [
68152
"csvs = [\n",
69153
" \"https://terminusdb.com/t/data/bikeshare/2011-capitalbikeshare-tripdata.csv\",\n",
@@ -109,7 +193,7 @@
109193
},
110194
{
111195
"cell_type": "code",
112-
"execution_count": null,
196+
"execution_count": 6,
113197
"metadata": {},
114198
"outputs": [],
115199
"source": [
@@ -194,11 +278,20 @@
194278
},
195279
{
196280
"cell_type": "code",
197-
"execution_count": null,
281+
"execution_count": 7,
198282
"metadata": {
199283
"scrolled": true
200284
},
201-
"outputs": [],
285+
"outputs": [
286+
{
287+
"name": "stderr",
288+
"output_type": "stream",
289+
"text": [
290+
"/Users/saran-7185/personal_repos/pycon-devsprint2020/terminusdb/terminusdb-bootstrap/env/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
291+
" and should_run_async(code)\n"
292+
]
293+
}
294+
],
202295
"source": [
203296
"def query_data(client):\n",
204297
" \"\"\"The query which query the database\n",
@@ -223,19 +316,167 @@
223316
},
224317
{
225318
"cell_type": "code",
226-
"execution_count": null,
319+
"execution_count": 8,
227320
"metadata": {},
228-
"outputs": [],
321+
"outputs": [
322+
{
323+
"name": "stderr",
324+
"output_type": "stream",
325+
"text": [
326+
"/Users/saran-7185/personal_repos/pycon-devsprint2020/terminusdb/terminusdb-bootstrap/env/lib/python3.7/site-packages/ipykernel/ipkernel.py:287: DeprecationWarning: `should_run_async` will not call `transform_cell` automatically in the future. Please pass the result to `transformed_cell` argument and any exception that happen during thetransform in `preprocessing_exc_tuple` in IPython 7.17 and above.\n",
327+
" and should_run_async(code)\n",
328+
"/Users/saran-7185/personal_repos/pycon-devsprint2020/terminusdb/terminusdb-bootstrap/env/lib/python3.7/site-packages/terminusdb_client/woqldataframe/woqlDataframe.py:251: UserWarning: DEPRECATED in 0.3.0: use result_to_df instead.\n",
329+
" warnings.warn(\"DEPRECATED in 0.3.0: use result_to_df instead.\")\n"
330+
]
331+
},
332+
{
333+
"data": {
334+
"text/html": [
335+
"<div>\n",
336+
"<style scoped>\n",
337+
" .dataframe tbody tr th:only-of-type {\n",
338+
" vertical-align: middle;\n",
339+
" }\n",
340+
"\n",
341+
" .dataframe tbody tr th {\n",
342+
" vertical-align: top;\n",
343+
" }\n",
344+
"\n",
345+
" .dataframe thead th {\n",
346+
" text-align: right;\n",
347+
" }\n",
348+
"</style>\n",
349+
"<table border=\"1\" class=\"dataframe\">\n",
350+
" <thead>\n",
351+
" <tr style=\"text-align: right;\">\n",
352+
" <th></th>\n",
353+
" <th>End</th>\n",
354+
" <th>End_Label</th>\n",
355+
" <th>Start</th>\n",
356+
" <th>Start_Label</th>\n",
357+
" </tr>\n",
358+
" </thead>\n",
359+
" <tbody>\n",
360+
" <tr>\n",
361+
" <th>0</th>\n",
362+
" <td>terminusdb:///data/Station_31010</td>\n",
363+
" <td>S Glebe &amp; Potomac Ave</td>\n",
364+
" <td>terminusdb:///data/Station_31007</td>\n",
365+
" <td>Crystal City Metro / 18th &amp; Bell St</td>\n",
366+
" </tr>\n",
367+
" <tr>\n",
368+
" <th>1</th>\n",
369+
" <td>terminusdb:///data/Station_31010</td>\n",
370+
" <td>S Glebe &amp; Potomac Ave</td>\n",
371+
" <td>terminusdb:///data/Station_31007</td>\n",
372+
" <td>Crystal City Metro / 18th &amp; Bell St</td>\n",
373+
" </tr>\n",
374+
" <tr>\n",
375+
" <th>2</th>\n",
376+
" <td>terminusdb:///data/Station_31229</td>\n",
377+
" <td>New Hampshire Ave &amp; T St NW</td>\n",
378+
" <td>terminusdb:///data/Station_31101</td>\n",
379+
" <td>14th &amp; V St NW</td>\n",
380+
" </tr>\n",
381+
" <tr>\n",
382+
" <th>3</th>\n",
383+
" <td>terminusdb:///data/Station_31229</td>\n",
384+
" <td>New Hampshire Ave &amp; T St NW</td>\n",
385+
" <td>terminusdb:///data/Station_31101</td>\n",
386+
" <td>14th &amp; V St NW</td>\n",
387+
" </tr>\n",
388+
" <tr>\n",
389+
" <th>4</th>\n",
390+
" <td>terminusdb:///data/Station_31207</td>\n",
391+
" <td>Georgia Ave and Fairmont St NW</td>\n",
392+
" <td>terminusdb:///data/Station_31101</td>\n",
393+
" <td>14th &amp; V St NW</td>\n",
394+
" </tr>\n",
395+
" <tr>\n",
396+
" <th>...</th>\n",
397+
" <td>...</td>\n",
398+
" <td>...</td>\n",
399+
" <td>...</td>\n",
400+
" <td>...</td>\n",
401+
" </tr>\n",
402+
" <tr>\n",
403+
" <th>1882</th>\n",
404+
" <td>terminusdb:///data/Station_31286</td>\n",
405+
" <td>11th &amp; O St NW</td>\n",
406+
" <td>terminusdb:///data/Station_31636</td>\n",
407+
" <td>New Jersey Ave &amp; N St NW/Dunbar HS</td>\n",
408+
" </tr>\n",
409+
" <tr>\n",
410+
" <th>1883</th>\n",
411+
" <td>terminusdb:///data/Station_31286</td>\n",
412+
" <td>11th &amp; O St NW</td>\n",
413+
" <td>terminusdb:///data/Station_31636</td>\n",
414+
" <td>New Jersey Ave &amp; N St NW/Dunbar HS</td>\n",
415+
" </tr>\n",
416+
" <tr>\n",
417+
" <th>1884</th>\n",
418+
" <td>terminusdb:///data/Station_31612</td>\n",
419+
" <td>D St &amp; Maryland Ave NE</td>\n",
420+
" <td>terminusdb:///data/Station_31641</td>\n",
421+
" <td>2nd St &amp; Massachusetts Ave NE</td>\n",
422+
" </tr>\n",
423+
" <tr>\n",
424+
" <th>1885</th>\n",
425+
" <td>terminusdb:///data/Station_31609</td>\n",
426+
" <td>Maine Ave &amp; 7th St SW</td>\n",
427+
" <td>terminusdb:///data/Station_31648</td>\n",
428+
" <td>Potomac Ave &amp; Half St SW</td>\n",
429+
" </tr>\n",
430+
" <tr>\n",
431+
" <th>1886</th>\n",
432+
" <td>terminusdb:///data/Station_32038</td>\n",
433+
" <td>King Farm Blvd &amp; Piccard Dr</td>\n",
434+
" <td>terminusdb:///data/Station_32045</td>\n",
435+
" <td>Shady Grove Metro West</td>\n",
436+
" </tr>\n",
437+
" </tbody>\n",
438+
"</table>\n",
439+
"<p>1887 rows × 4 columns</p>\n",
440+
"</div>"
441+
],
442+
"text/plain": [
443+
" End End_Label \\\n",
444+
"0 terminusdb:///data/Station_31010 S Glebe & Potomac Ave \n",
445+
"1 terminusdb:///data/Station_31010 S Glebe & Potomac Ave \n",
446+
"2 terminusdb:///data/Station_31229 New Hampshire Ave & T St NW \n",
447+
"3 terminusdb:///data/Station_31229 New Hampshire Ave & T St NW \n",
448+
"4 terminusdb:///data/Station_31207 Georgia Ave and Fairmont St NW \n",
449+
"... ... ... \n",
450+
"1882 terminusdb:///data/Station_31286 11th & O St NW \n",
451+
"1883 terminusdb:///data/Station_31286 11th & O St NW \n",
452+
"1884 terminusdb:///data/Station_31612 D St & Maryland Ave NE \n",
453+
"1885 terminusdb:///data/Station_31609 Maine Ave & 7th St SW \n",
454+
"1886 terminusdb:///data/Station_32038 King Farm Blvd & Piccard Dr \n",
455+
"\n",
456+
" Start Start_Label \n",
457+
"0 terminusdb:///data/Station_31007 Crystal City Metro / 18th & Bell St \n",
458+
"1 terminusdb:///data/Station_31007 Crystal City Metro / 18th & Bell St \n",
459+
"2 terminusdb:///data/Station_31101 14th & V St NW \n",
460+
"3 terminusdb:///data/Station_31101 14th & V St NW \n",
461+
"4 terminusdb:///data/Station_31101 14th & V St NW \n",
462+
"... ... ... \n",
463+
"1882 terminusdb:///data/Station_31636 New Jersey Ave & N St NW/Dunbar HS \n",
464+
"1883 terminusdb:///data/Station_31636 New Jersey Ave & N St NW/Dunbar HS \n",
465+
"1884 terminusdb:///data/Station_31641 2nd St & Massachusetts Ave NE \n",
466+
"1885 terminusdb:///data/Station_31648 Potomac Ave & Half St SW \n",
467+
"1886 terminusdb:///data/Station_32045 Shady Grove Metro West \n",
468+
"\n",
469+
"[1887 rows x 4 columns]"
470+
]
471+
},
472+
"execution_count": 8,
473+
"metadata": {},
474+
"output_type": "execute_result"
475+
}
476+
],
229477
"source": [
230478
"woqldataframe.query_to_df(result)"
231479
]
232-
},
233-
{
234-
"cell_type": "code",
235-
"execution_count": null,
236-
"metadata": {},
237-
"outputs": [],
238-
"source": []
239480
}
240481
],
241482
"metadata": {
@@ -254,7 +495,7 @@
254495
"name": "python",
255496
"nbconvert_exporter": "python",
256497
"pygments_lexer": "ipython3",
257-
"version": "3.8.5"
498+
"version": "3.7.5"
258499
}
259500
},
260501
"nbformat": 4,

0 commit comments

Comments
 (0)