krassowski / jupyterlab-citation-manager

Citation Manager for JupyterLab using Zotero Web API
BSD 3-Clause "New" or "Revised" License
67 stars 2 forks source link

local Zotero access (no API) #37

Open jangenoe opened 3 years ago

jangenoe commented 3 years ago

It is great that the cite2c is now ported to jupyterlab. I note that the users reference database is accessed online using the API key, as already was done in the cite2c. However, this online access is not always possible, e.g. when traveling by train of plane ...

Many of the citation manager users are already using Zotero on their PC, and when Zotero with BetterBibTex is running, citations can also be entered from the local Zotero database, as is done in:

https://github.com/retorquere/zotero-citations https://github.com/mblode/vscode-zotero

Moreover, when Zotero is running and the user is browsing in Zotero on a specific folder or paper (typically when this is being explored), this topic can already be selected also in the extension.

In this view I believe it can be useful to enable also the access to the local database without API key.

PS: it is also great that you suggest in the read-me how to set the path to the csl-styles folder. Zotero users have usually already quite a collection of csl files in their $Zotero-home-dir/styles folder. They can just add this folder to their "jupyter --paths".

krassowski commented 3 years ago
  1. We already cache the Zotero collections in the browser database, so this extension works properly when offline, and once back online it syncs with the Zotero API using established protocols; I agree that an issue may arise when you want to use the client to enter a new citation manually (when offline) and then to sync the collections in JupyterLab; this could potentially be solved in two ways:
    • a) you could install Zotero dataserver implementing Zotero Web API v3 locally and sync through it
    • b) we could support some basic editing/creation of citations
    • c) we could connect directly to the local Zotero client

Let's discuss (c) in more details:

  1. It is not possible for the frontend to have a direct connection with the local Zotero client without developing a browser extension (see how Zotero implements Google Docs integration). Many developers had attempted this, but Zotero API blocks the connections on CORS policy level and there is no way for the user to allow external traffic in; there are a few discussions on it on the zotero-dev group: https://groups.google.com/g/zotero-dev/search?q=cors
  2. We could connect from backend to the Zotero client installed on backend but because of JupyterHub and friends, the machine where the server extension lives and the machine where the client thinks the JupyterLab is running are often two different computers

This is why this extension uses web API first and foremost; if someone wants to develop a new citation provider by querying the local instance of Zotero (despite the limitation described in the 3rd point i.e. it will be useless for users who connect to remote jupyter servers) they are welcome to open a draft pull request; it would need to be composed of a server extension that would interact with the local Zotero client and from a frontend IReferenceProvider which would interact with this server extension, implementing:

https://github.com/krassowski/jupyterlab-citation-manager/blob/bc366a8f7ce0a9f9340c33c982da125d815da7b5/src/types.ts#L224-L246

As does the Zotero Web API Client:

https://github.com/krassowski/jupyterlab-citation-manager/blob/bc366a8f7ce0a9f9340c33c982da125d815da7b5/src/zotero.ts#L119-L498

But please note that it should not use the native Zotero picker, but instead only sync collection data in JSON CSL format.