Skip to content

Commit

Permalink
add interactive_login and jupyter notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
jcschaff committed May 30, 2024
1 parent d8232d3 commit eb343e2
Show file tree
Hide file tree
Showing 6 changed files with 2,139 additions and 39 deletions.
28 changes: 8 additions & 20 deletions .openapi-generator-ignore
Original file line number Diff line number Diff line change
@@ -1,23 +1,11 @@
# OpenAPI Generator Ignore
# Generated by openapi-generator https://github.com/openapitools/openapi-generator

# Use this file to prevent files from being overwritten by the generator.
# The patterns follow closely to .gitignore or .dockerignore.

# As an example, the C# client generator defines ApiClient.cs.
# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line:
#ApiClient.cs

# You can match any string of characters against a directory, file or extension with a single asterisk (*):
#foo/*/qux
# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux

# You can recursively match patterns against a directory, file or extension with a double asterisk (**):
#foo/**/qux
# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux

# You can also negate patterns with an exclamation (!).
# For example, you can ignore all files in a docs folder with the file extension .md:
#docs/*.md
# Then explicitly reverse the ignore rule for a single file:
#!docs/README.md
git_push.sh
requirements.txt
setup.cfg
setup.py
test-requirements.txt
.gitlab-ci.yml
.travis.yml
pyproject.toml
213 changes: 213 additions & 0 deletions example_latest.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
{
"cells": [
{
"cell_type": "code",
"source": [
"from vcell_api_client.api_client import ApiClient, Configuration\n",
"from vcell_api_client.auth.auth_utils import login_interactive\n",
"from vcell_api_client import Publication\n",
"from vcell_api_client.api.publication_resource_api import PublicationResourceApi"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-05-30T18:11:43.313995Z",
"start_time": "2024-05-30T18:11:43.309359Z"
}
},
"id": "5e183b4a68315dfe",
"outputs": [],
"execution_count": 2
},
{
"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",
"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-30T18:11:46.721743Z",
"start_time": "2024-05-30T18:11:46.718117Z"
}
},
"id": "902c6d3a8dc70af",
"outputs": [],
"execution_count": 3
},
{
"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",
"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-30T18:11:50.556705Z",
"start_time": "2024-05-30T18:11:50.274764Z"
}
},
"id": "9ba5b1ac2df17231",
"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"
}
],
"execution_count": 4
},
{
"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",
"id": "f56d96abf59682dd",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-05-30T18:12:01.401238Z",
"start_time": "2024-05-30T18:11:54.267319Z"
}
},
"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.\")"
],
"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"
}
],
"execution_count": 5
},
{
"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",
"id": "8f95b36e4437ccbb",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2024-05-30T18:12:07.915716Z",
"start_time": "2024-05-30T18:12:07.748765Z"
}
},
"source": [
"publication_api = PublicationResourceApi(authenticated_client)\n",
"pubs: list[Publication] = publication_api.get_publications()\n",
"display(pubs[0])"
],
"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"
}
],
"execution_count": 6
},
{
"cell_type": "code",
"id": "ed266f9194abb748",
"metadata": {
"collapsed": false
},
"source": [],
"outputs": [],
"execution_count": null
}
],
"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
}
Loading

0 comments on commit eb343e2

Please sign in to comment.