|
2 | 2 | "cells": [
|
3 | 3 | {
|
4 | 4 | "cell_type": "code",
|
5 |
| - "execution_count": null, |
| 5 | + "execution_count": 1, |
6 | 6 | "metadata": {},
|
7 | 7 | "outputs": [],
|
8 | 8 | "source": [
|
9 |
| - "import terminusdb_client as woql\n", |
10 |
| - "from terminusdb_client import woqldataframe\n", |
11 | 9 | "from terminusdb_client import WOQLQuery\n",
|
| 10 | + "from terminusdb_client import WOQLClient\n", |
| 11 | + "from terminusdb_client import woqldataframe\n", |
12 | 12 | "\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", |
16 | 16 | "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", |
23 | 21 | "\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)" |
29 | 24 | ]
|
30 | 25 | },
|
31 | 26 | {
|
32 | 27 | "cell_type": "code",
|
33 |
| - "execution_count": null, |
| 28 | + "execution_count": 2, |
34 | 29 | "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 | + ], |
36 | 111 | "source": [
|
37 | 112 | "def create_schema(client, commit_msg):\n",
|
38 | 113 | " \"\"\"The query which creates the schema\n",
|
|
61 | 136 | },
|
62 | 137 | {
|
63 | 138 | "cell_type": "code",
|
64 |
| - "execution_count": null, |
| 139 | + "execution_count": 5, |
65 | 140 | "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 | + ], |
67 | 151 | "source": [
|
68 | 152 | "csvs = [\n",
|
69 | 153 | " \"https://terminusdb.com/t/data/bikeshare/2011-capitalbikeshare-tripdata.csv\",\n",
|
|
109 | 193 | },
|
110 | 194 | {
|
111 | 195 | "cell_type": "code",
|
112 |
| - "execution_count": null, |
| 196 | + "execution_count": 6, |
113 | 197 | "metadata": {},
|
114 | 198 | "outputs": [],
|
115 | 199 | "source": [
|
|
194 | 278 | },
|
195 | 279 | {
|
196 | 280 | "cell_type": "code",
|
197 |
| - "execution_count": null, |
| 281 | + "execution_count": 7, |
198 | 282 | "metadata": {
|
199 | 283 | "scrolled": true
|
200 | 284 | },
|
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 | + ], |
202 | 295 | "source": [
|
203 | 296 | "def query_data(client):\n",
|
204 | 297 | " \"\"\"The query which query the database\n",
|
|
223 | 316 | },
|
224 | 317 | {
|
225 | 318 | "cell_type": "code",
|
226 |
| - "execution_count": null, |
| 319 | + "execution_count": 8, |
227 | 320 | "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 & Potomac Ave</td>\n", |
| 364 | + " <td>terminusdb:///data/Station_31007</td>\n", |
| 365 | + " <td>Crystal City Metro / 18th & 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 & Potomac Ave</td>\n", |
| 371 | + " <td>terminusdb:///data/Station_31007</td>\n", |
| 372 | + " <td>Crystal City Metro / 18th & 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 & T St NW</td>\n", |
| 378 | + " <td>terminusdb:///data/Station_31101</td>\n", |
| 379 | + " <td>14th & 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 & T St NW</td>\n", |
| 385 | + " <td>terminusdb:///data/Station_31101</td>\n", |
| 386 | + " <td>14th & 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 & 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 & O St NW</td>\n", |
| 406 | + " <td>terminusdb:///data/Station_31636</td>\n", |
| 407 | + " <td>New Jersey Ave & 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 & O St NW</td>\n", |
| 413 | + " <td>terminusdb:///data/Station_31636</td>\n", |
| 414 | + " <td>New Jersey Ave & 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 & Maryland Ave NE</td>\n", |
| 420 | + " <td>terminusdb:///data/Station_31641</td>\n", |
| 421 | + " <td>2nd St & 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 & 7th St SW</td>\n", |
| 427 | + " <td>terminusdb:///data/Station_31648</td>\n", |
| 428 | + " <td>Potomac Ave & 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 & 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 | + ], |
229 | 477 | "source": [
|
230 | 478 | "woqldataframe.query_to_df(result)"
|
231 | 479 | ]
|
232 |
| - }, |
233 |
| - { |
234 |
| - "cell_type": "code", |
235 |
| - "execution_count": null, |
236 |
| - "metadata": {}, |
237 |
| - "outputs": [], |
238 |
| - "source": [] |
239 | 480 | }
|
240 | 481 | ],
|
241 | 482 | "metadata": {
|
|
254 | 495 | "name": "python",
|
255 | 496 | "nbconvert_exporter": "python",
|
256 | 497 | "pygments_lexer": "ipython3",
|
257 |
| - "version": "3.8.5" |
| 498 | + "version": "3.7.5" |
258 | 499 | }
|
259 | 500 | },
|
260 | 501 | "nbformat": 4,
|
|
0 commit comments