pyzotero

1.11.0 · active · verified Fri Apr 17

Python wrapper for the Zotero API, enabling programmatic access to Zotero libraries for managing research references, collections, and items. It's currently at version 1.11.0 and typically releases new versions every few months, often including bug fixes and minor enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart initializes the Zotero client and fetches the first few collections and items from your library. It demonstrates accessing nested data fields and uses environment variables for secure credential management.

import os
from pyzotero import Zotero

# Your Zotero user ID or group ID
library_id = os.environ.get('ZOTERO_LIBRARY_ID', 'YOUR_LIBRARY_ID') # Replace 'YOUR_LIBRARY_ID' if not using env var
# Your Zotero API key
api_key = os.environ.get('ZOTERO_API_KEY', 'YOUR_API_KEY') # Replace 'YOUR_API_KEY' if not using env var

# 'user' for personal library, 'group' for group library
library_type = 'user'

if not library_id or not api_key:
    print("Please set ZOTERO_LIBRARY_ID and ZOTERO_API_KEY environment variables or replace placeholders.")
else:
    try:
        # Initialize Zotero object
        zot = Zotero(library_id, library_type, api_key)

        # Fetch top-level collections
        collections = zot.collections()
        print(f"Found {len(collections)} collections.")
        if collections:
            print(f"First collection name: {collections[0]['data']['name']}")

        # Fetch 5 items from the library
        items = zot.items(limit=5)
        print(f"Found {len(items)} items.")
        if items:
            print(f"First item title: {items[0]['data']['title']}")

    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →