Zotero libraries¶
pkpdbib.zotero_tools provides programmatic access to Zotero libraries via pyzotero and creates tables of the tags of their items with polars.
Access¶
Access needs an API key with read access to the library, created at zotero.org/settings/keys/new. The id of a group library is found by opening the page of the group via zotero.org/groups and hovering over the link to the group settings, it is the integer after /groups/.
Keep the API key out of the source code, e.g., in an environment variable:
import os
from pkpdbib.zotero_tools import create_zot_client, get_items
zot = create_zot_client(
api_key=os.environ["ZOTERO_API_KEY"],
library_id=4979949,
library_type="group",
)
items = get_items(zot) # all top level items
Tag tables¶
The curation of a library is recorded in the tags of its items, e.g., pkdb for items curated in PK-DB or species:human. create_tag_table creates a table with one row per item and one boolean column per selected tag, in addition to the DOI and the PubMed id of the item:
from pkpdbib.zotero_tools import create_tag_table
df = create_tag_table(
items,
tags_set={"pkdb", "has_simulation"},
tag_prefixes=["species:", "data:"],
)
df.write_csv("tags.csv")
A complete example is examples/zotero_tags.py. See the API reference for all functions.