Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add vcell api client #1

Merged
merged 9 commits into from
Jan 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
python-version: ["3.9", "3.10", "3.11", "3.12"]
fail-fast: false
defaults:
run:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ cython_debug/
.idea/

test_output_1/

.python-version

**/.DS_Store
1 change: 1 addition & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ repos:
hooks:
- id: ruff
args: [--exit-non-zero-on-fix]
exclude: 'pyvcell/api/.*\.py'
- id: ruff-format

- repo: https://github.com/pre-commit/mirrors-prettier
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ check: ## Run code quality tools.
@echo "🚀 Static type checking: Running mypy"
@poetry run mypy
@echo "🚀 Checking for obsolete dependencies: Running deptry"
@poetry run deptry .
@poetry run deptry --exclude .venv .

.PHONY: test
test: ## Test the code with pytest
Expand Down
11 changes: 10 additions & 1 deletion docs/modules.md
Original file line number Diff line number Diff line change
@@ -1 +1,10 @@
::: pyvcell.foo
# Modules

## pyvcell

::: pyvcell
handler: python
options:
show_root_heading: true
show_source: true
show_signature_annotations: true
216 changes: 216 additions & 0 deletions examples/vcell_publications.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
{
"cells": [
{
"cell_type": "code",
"source": [
"from pyvcell.api.vcell_client import ApiClient, Configuration, PublicationResourceApi\n",
"from pyvcell.api.vcell_client.auth.auth_utils import login_interactive\n",
"from pyvcell.api.vcell_client.models import Publication"
],
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2025-01-23T07:43:37.703710Z",
"start_time": "2025-01-23T07:43:37.701027Z"
}
},
"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": "2025-01-23T07:43:37.725514Z",
"start_time": "2025-01-23T07:43:37.723335Z"
}
},
"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": "2025-01-23T07:43:38.028844Z",
"start_time": "2025-01-23T07:43:37.735773Z"
}
},
"id": "9ba5b1ac2df17231",
"outputs": [
{
"data": {
"text/plain": [
"Publication(pub_key=279906235, title='A continuum model of mechanosensation based on contractility kit assembly', authors=['Dolgitzer', ' D.', ' Plaza-Rodríguez', ' A. I.', ' Iglesias', ' M. A.', ' Jacob', ' M. A. C.', ' Todd', ' B.', ' Robinson', ' D. N.', ' & Iglesias', ' P. A.'], year=2024, citation='Biophys J. 2024 Nov 8:S0006-3495(24)00708-2', pubmedid='39521955', doi='https://doi.org/10.1016/j.bpj.2024.10.020', endnoteid=0, url='url', wittid=0, biomodel_refs=[BiomodelRef(bm_key=279851639, name='Dolgitzer 2025 A Continuum Model of Mechanosensation Based on Contractility Kit Assembly', owner_name='Dolgitzer', owner_key=259537152, version_flag=3)], mathmodel_refs=[], var_date=datetime.date(2024, 11, 26))"
]
},
"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": "2025-01-23T07:43:46.823079Z",
"start_time": "2025-01-23T07:43:38.037782Z"
}
},
"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": "2025-01-23T07:43:47.020349Z",
"start_time": "2025-01-23T07:43:46.852654Z"
}
},
"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=279906235, title='A continuum model of mechanosensation based on contractility kit assembly', authors=['Dolgitzer', ' D.', ' Plaza-Rodríguez', ' A. I.', ' Iglesias', ' M. A.', ' Jacob', ' M. A. C.', ' Todd', ' B.', ' Robinson', ' D. N.', ' & Iglesias', ' P. A.'], year=2024, citation='Biophys J. 2024 Nov 8:S0006-3495(24)00708-2', pubmedid='39521955', doi='https://doi.org/10.1016/j.bpj.2024.10.020', endnoteid=0, url='url', wittid=0, biomodel_refs=[BiomodelRef(bm_key=279851639, name='Dolgitzer 2025 A Continuum Model of Mechanosensation Based on Contractility Kit Assembly', owner_name='Dolgitzer', owner_key=259537152, version_flag=3)], mathmodel_refs=[], var_date=datetime.date(2024, 11, 26))"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"execution_count": 6
},
{
"cell_type": "code",
"id": "ed266f9194abb748",
"metadata": {
"collapsed": false,
"ExecuteTime": {
"end_time": "2025-01-23T07:43:47.026801Z",
"start_time": "2025-01-23T07:43:47.025477Z"
}
},
"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
Loading