{ "cells": [ { "cell_type": "code", "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "/Users/schaff/Documents/workspace/vcell/python-restclient/.venv/lib/python3.12/site-packages/pydantic/_internal/_fields.py:151: UserWarning: Field \"model_key\" has conflict with protected namespace \"model_\".\n", "\n", "You may be able to resolve this warning by setting `model_config['protected_namespaces'] = ()`.\n", " warnings.warn(\n" ] } ], "source": [ "from vcell_client.api_client import ApiClient, Configuration\n", "from vcell_client.auth.auth_utils import login_interactive\n", "from vcell_client import Publication\n", "from vcell_client.api.publication_resource_api import PublicationResourceApi" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-01T21:12:53.063024Z", "start_time": "2024-05-01T21:12:52.850129Z" } }, "id": "5e183b4a68315dfe", "execution_count": 1 }, { "cell_type": "markdown", "source": [ "# VCell API Client usage\n", "1. as a public user (no authentication)\n", "2. as an authenticated user (with authentication)" ], "metadata": { "collapsed": false }, "id": "d11f5830839dbfb4" }, { "cell_type": "markdown", "source": [ "## 1) Create anonymous API Client - access to public resources" ], "metadata": { "collapsed": false }, "id": "524d1696c6c50b83" }, { "cell_type": "code", "outputs": [], "source": [ "api_url: str = \"https://vcell-dev.cam.uchc.edu\" # vcell base url\n", "\n", "public_client = ApiClient(configuration=Configuration(host=api_url))" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-01T21:13:12.872880Z", "start_time": "2024-05-01T21:13:12.870503Z" } }, "id": "902c6d3a8dc70af", "execution_count": 2 }, { "cell_type": "markdown", "source": [ "### Test Publication API - without authentication\n", "1. get publications - doesn't need authentication/authorization" ], "metadata": { "collapsed": false }, "id": "b12dfb281d589869" }, { "cell_type": "code", "outputs": [ { "data": { "text/plain": "Publication(pub_key=270069811, title='K+ and pH homeostasis in plant cells is controlled by a synchronized K+ /H+ antiport at the plasma and vacuolar membrane', authors=['Li, K.', 'Grauschopf, C.', 'Hedrich, R.', 'Dreyer, I.', 'Konrad, K. R.'], year=2024, citation='New Phytol . 2024 Feb;241(4):1525-1542', pubmedid='38017688', doi='10.1111/nph.19436', endnoteid=None, url=None, wittid=-1, biomodel_refs=[BiomodelRef(bm_key=270051643, name='Li_et_al_2024_NewPhytol_Guard_Cell_Homeostats', owner_name='idreyer', owner_key=97134174, version_flag=3)], mathmodel_refs=[], var_date=datetime.date(2023, 11, 28))" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "public_publication_api = PublicationResourceApi(public_client)\n", "pubs: list[Publication] = public_publication_api.get_publications()\n", "display(pubs[0])" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-01T21:13:15.493227Z", "start_time": "2024-05-01T21:13:15.190372Z" } }, "id": "9ba5b1ac2df17231", "execution_count": 3 }, { "cell_type": "markdown", "source": [ "## 2) invoke VCell API as an authenticated user\n", "This will open a browser window to login into VCell using Auth0. After login, the browser will redirect to the VCell webapp '/success_login'. `api_client` will be authenticated for VCell API requests. " ], "metadata": { "collapsed": false }, "id": "6444e342beaccd4d" }, { "cell_type": "code", "execution_count": 6, "id": "f56d96abf59682dd", "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-01T21:14:26.398587Z", "start_time": "2024-05-01T21:14:25.485352Z" } }, "outputs": [ { "data": { "text/plain": "'may loose focus to the browser window for login, switch back to this notebook after login.'" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "client_id: str = 'cjoWhd7W8A8znf7Z7vizyvKJCiqTgRtf' # default client id for standalone VCell clients\n", "issuer_url: str = 'https://dev-dzhx7i2db3x3kkvq.us.auth0.com' # Auth0 issuer url for VCell\n", "\n", "authenticated_client = login_interactive(api_base_url=api_url, client_id=client_id, issuer_url=issuer_url)\n", "display(\"may loose focus to the browser window for login, switch back to this notebook after login.\")" ] }, { "cell_type": "markdown", "id": "a0e558b807038809", "metadata": { "collapsed": false }, "source": [ "### Test Publication API\n", "1. get publications - also doesn't need authentication/authorization" ] }, { "cell_type": "code", "execution_count": 7, "id": "8f95b36e4437ccbb", "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2024-05-01T21:14:34.427704Z", "start_time": "2024-05-01T21:14:34.148156Z" } }, "outputs": [ { "data": { "text/plain": "Publication(pub_key=270069811, title='K+ and pH homeostasis in plant cells is controlled by a synchronized K+ /H+ antiport at the plasma and vacuolar membrane', authors=['Li, K.', 'Grauschopf, C.', 'Hedrich, R.', 'Dreyer, I.', 'Konrad, K. R.'], year=2024, citation='New Phytol . 2024 Feb;241(4):1525-1542', pubmedid='38017688', doi='10.1111/nph.19436', endnoteid=None, url=None, wittid=-1, biomodel_refs=[BiomodelRef(bm_key=270051643, name='Li_et_al_2024_NewPhytol_Guard_Cell_Homeostats', owner_name='idreyer', owner_key=97134174, version_flag=3)], mathmodel_refs=[], var_date=datetime.date(2023, 11, 28))" }, "metadata": {}, "output_type": "display_data" } ], "source": [ "publication_api = PublicationResourceApi(authenticated_client)\n", "pubs: list[Publication] = publication_api.get_publications()\n", "display(pubs[0])" ] }, { "cell_type": "code", "execution_count": null, "id": "ed266f9194abb748", "metadata": { "collapsed": false }, "outputs": [], "source": [] } ], "metadata": { "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.12.2" } }, "nbformat": 4, "nbformat_minor": 5 }