跳到主要内容

Zotero 文献库

收藏0

用 pyzotero 程序化管理 Zotero 文献库:检索条目、新建与更新条目、整理分类与标签、导出引用格式、上传 PDF 附件,支持 Web API 与本地 API。

让 AI 安装

星光尘缘LV2最新版本 0.1.0更新于 2026-11-24下载 0 次

references/read-api.md

4.3 KB查看排版效果
1# Read API Methods
2
3## Retrieving Items
4
5```python
6# One page of items (100 per call by default; excludes trash)
7items = zot.items()
8
9# Top-level items only (excludes attachments/notes that are children)
10top = zot.top(limit=25)
11
12# A specific item by key
13item = zot.item('ITEMKEY')
14
15# Up to 50 specific items in ONE request
16subset = zot.items(itemKey=','.join(['KEY1', 'KEY2', 'KEY3']))
17# get_subset([...]) instead makes one single-item request per key (up to 50).
18
19# Items from trash
20trash = zot.trash()
21
22# Deleted items (requires 'since' parameter)
23deleted = zot.deleted(since=1000)
24
25# Items from "My Publications"
26pubs = zot.publications() # user libraries only
27
28# Count all items
29count = zot.count_items()
30
31# Count top-level items
32n = zot.num_items()
33```
34
35## Item Data Structure
36
37Items are returned as dicts. Data lives in `item['data']`:
38
39```python
40item = zot.item('VDNIEAPH') # a dict, not a one-element list
41title = item['data'].get('title', '')
42item_type = item['data']['itemType']
43creators = item['data'].get('creators', [])
44tags = item['data']['tags']
45key = item['data']['key']
46version = item['data']['version']
47collections = item['data']['collections']
48doi = item['data'].get('DOI', '')
49```
50
51## Child Items
52
53```python
54# Get child items (notes, attachments) of a parent
55children = zot.children('PARENTKEY')
56```
57
58## Retrieving Collections
59
60```python
61# One page of collections (including subcollections)
62collections = zot.collections()
63
64# Top-level collections only
65top_collections = zot.collections_top()
66
67# A specific collection
68collection = zot.collection('COLLECTIONKEY')
69
70# Sub-collections of a collection
71sub = zot.collections_sub('COLLECTIONKEY')
72
73# All collections and sub-collections in a flat list
74all_cols = zot.all_collections()
75# Or from a specific collection down:
76all_cols = zot.all_collections('COLLECTIONKEY')
77
78# Items in a specific collection (not sub-collections)
79col_items = zot.collection_items('COLLECTIONKEY')
80
81# Top-level items in a specific collection
82col_top = zot.collection_items_top('COLLECTIONKEY')
83
84# Count items in a collection
85n = zot.num_collectionitems('COLLECTIONKEY')
86```
87
88## Retrieving Tags
89
90```python
91# All tags in the library
92tags = zot.everything(zot.tags())
93
94# Tags from a specific item
95item_tags = zot.item_tags('ITEMKEY')
96
97# Tags in a collection
98col_tags = zot.collection_tags('COLLECTIONKEY')
99```
100
101## Retrieving Groups
102
103```python
104# Use a client initialized with the USER ID, not a group ID.
105groups = zot.everything(zot.groups())
106# /users/{userID}/groups: inspect each group's access before writing.
107```
108
109## Version Information
110
111```python
112# Last modified version of the library
113version = zot.last_modified_version()
114
115# Item versions dict {key: version}
116item_versions = zot.item_versions()
117
118# Collection versions dict {key: version}
119col_versions = zot.collection_versions()
120
121# Changes since a known version (for syncing)
122changed_items = zot.item_versions(since=1000)
123```
124
125## Library Settings
126
127```python
128settings = zot.settings()
129# Returns a setting-name mapping; values carry version and value.
130# Available settings depend on the library; do not assume a fixed set.
131# Use 'since' to get only changes:
132new_settings = zot.settings(since=500)
133```
134
135## Saved Searches
136
137```python
138searches = zot.searches()
139# Retrieves saved search metadata (not results)
140```
141
142## Endpoint and Sync Boundaries
143
144All library routes use `/users/{userID}` or `/groups/{groupID}` under `https://api.zotero.org`. Item reads use `/items`, `/items/top`, `/items/trash`, `/items/{key}`, and `/items/{key}/children`. Collections use `/collections`, `/collections/top`, `/collections/{key}`, `/collections/{key}/collections`, and `/collections/{key}/items[/top]`. Tags use `/tags`, `/items/{key}/tags`, or `/collections/{key}/tags`. `settings()`, `searches()`, and `deleted(since=...)` use the corresponding library routes. `publications()` uses `/users/{userID}/publications/items`.
145
146`deleted()` returns a dict of deleted keys grouped by object type, not item records. A complete incremental sync needs changed objects **and** deletions, plus `includeTrashed=1` when tracking trash transitions. Save the library version from the completed read sequence, not a later unrelated call; restart/reconcile if versions change during pagination. See [official syncing rules](https://www.zotero.org/support/dev/web_api/v3/syncing). `last_modified_version()` makes its own multi-object read.

文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。