跳到主要内容

Zotero 文献库

收藏0

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

让 AI 安装

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

references/pagination.md

2.4 KB查看排版效果
1# Pagination: follow(), everything(), Generators
2
3Pyzotero returns 100 items by default. Use these methods to retrieve more.
4
5## everything() — Retrieve All Results
6
7The simplest way to get all items:
8
9```python
10# All items in the library
11all_items = zot.everything(zot.items())
12
13# All top-level items
14all_top = zot.everything(zot.top())
15
16# All items in a collection
17all_col = zot.everything(zot.collection_items('COLKEY'))
18
19# All items matching a search
20all_results = zot.everything(zot.items(q='machine learning', itemType='journalArticle'))
21```
22
23Use `everything()` with list-returning endpoints (items, collections, tags, searches) and BibTeX databases. Do not pass dict responses (`format=versions`, `deleted`, `settings`) or bytes (`format=keys`): their iteration semantics differ.
24
25## follow() — Sequential Pagination
26
27```python
28# Retrieve items in batches, manually advancing the page
29first_batch = zot.top(limit=25)
30second_batch = zot.follow() # next 25 items
31third_batch = zot.follow() # next 25 items
32```
33
34`follow()` returns `None` when no next-page link exists. `iterfollow()` and `makeiter()` end by raising `StopIteration` through normal generator exhaustion. Do not interleave other reads on the same client while paging: they replace its pagination links.
35
36## iterfollow() — Generator
37
38```python
39# Create a generator over follow()
40first = zot.top(limit=10)
41lazy = zot.iterfollow()
42
43# Retrieve subsequent pages
44second = next(lazy)
45third = next(lazy)
46```
47
48## makeiter() — Generator over Any Method
49
50```python
51# Create a generator directly from a method call
52gen = zot.makeiter(zot.top(limit=25))
53
54page1 = next(gen) # first 25 items, fetched AGAIN by makeiter()
55page2 = next(gen) # next 25 items
56# Raises StopIteration when exhausted
57```
58
59## Manual start/limit Pagination
60
61```python
62page_size = 50
63offset = 0
64
65while True:
66 batch = zot.items(limit=page_size, start=offset)
67 if not batch:
68 break
69 # process batch
70 for item in batch:
71 process(item)
72 offset += page_size
73```
74
75## Performance Notes
76
77- `everything()` makes multiple API calls sequentially; large libraries may take time.
78- For incremental synchronization, combine `since=version` with `deleted(since=version)` and account for changes during paging; see [read-api.md](read-api.md).
79- The raw local API has no default limit, but Pyzotero still injects 100 unless you pass `limit=None`. Local reads can use `zot.items(limit=None)`; remote JSON reads remain paginated.

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