Skip to main content

Are you a scientist with a bunch of Zotero entries that have 1000+ authors (*cough* the LIGO Scientific Collaboration *cough*)? Is your bibtex file huge, and does the Sync with Zotero option break whenever you try to load a bibtext file into Overleaf (with an unhelpful error message)? Then you should update your library to reduce the number of authors with each entry!

WARNING: For the love of god, save a copy of your Zotero library before you do this! I have obviously not tested this rigorously and am neither an expert in Python or the databases that Zotero uses. I did this by renaming my local Zotero library (in your home directory in Mac) to something like “zotero_backup”. This was also necessary since you’ll need to rebuild your local library from the remote one at the end.

While there are presumably a bunch of different ways to do, I went with the Pyzotero package. It provides a direct (and very easy) API to your online Zotero. You can install it with either pip or conda:

pip install pyzotero


conda config --add channels conda-forge && conda install pyzotero

You can then, from python, directly access your online Zotero library. To do that, you’ll need your Zotero username and an API key (following the instructions here). Once you’ve set that up, you can connect to your Zotero library and import all the entries with:

from pyzotero import zotero
zot = zotero.Zotero(<your library ID>,'user',<your API key>)
items = zot.everything(zot.items())

Note this may take a minute or two, depending on how large your library is. Once that’s done, you can just iterate through the items in the library (it produces a list of python dictionaries), and delete however many authors you want from the end of each entry. Here, I decided to delete every author past the first 50:

for i, item in enumerate(items):
    if 'creators' in item['data'].keys():
        num = len(item['data']['creators'])
        if num > 50:
            for j in reversed(range(50,num)):
                del items[i]['data']['creators'][j]

(yes I’m sure there’s a cleaner way to do this; I wanted to get back to writing quickly). Once that’s done, you just need to update your entries in the remote repository:

for idx,item in enumerate(items):
        print("Failed at item "+str(idx))

I found that the only entries that failed where my own papers (probably something to do with the “My Publications” option). Once that is done remotely, you can open Zotero again locally, download your new (reduced author list) Zotero library back from the server, and you should be good to go!

ADDENDUM: if you want to use the same LaTex citation keys between the desktop and online versions (which is really the whole point), you’ll need to add the citation keys to the “Extra” part of the Zotero database. This can be done by just selecting all the entries in your library, right clicking, and clicking Better BibTex -> Pin BibTex Key. Check out this answer on Stack Overflow. Once that’s done, you can sync your local library (sync button in the upper right hand corner) and you should be good to go!

Comments are closed.