跳到主要内容

Zotero 文献库

收藏0

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

让 AI 安装

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

references/exports.md

3.9 KB查看排版效果
1# Export Formats
2
3These examples target Pyzotero 1.15.2. Set the format and its parameters together on the read call. Calling `add_parameters(format='bibtex')` and then `top(limit=50)` resets the format to JSON in this release; the result will not have `.entries`.
4
5## BibTeX
6
7```python
8import bibtexparser
9
10bibtex_db = zot.top(format='bibtex', limit=50)
11# bibtexparser 1.x BibDatabase
12for entry in bibtex_db.entries:
13 print(entry.get('title'), entry.get('author'))
14with open('library.bib', 'w', encoding='utf-8') as f:
15 bibtexparser.dump(bibtex_db, f)
16```
17
18Use `zot.everything(zot.top(format='bibtex', limit=100))` for a complete paginated remote export. The bibliography reflects Zotero's stored metadata; confirm DOI, author, title, and publication details before citing.
19
20## CSL-JSON
21
22```python
23# Direct CSL export wraps the array in an 'items' member.
24csl_export = zot.items(format='csljson', limit=50)
25csl_items = csl_export['items']
26
27# Or retain Zotero metadata alongside per-item CSL data
28records = zot.items(format='json', include='data,csljson', limit=50)
29csl_items = [record['csljson'] for record in records]
30```
31
32## Bibliography HTML and Citations
33
34```python
35# Individual references embedded in JSON (also supported by the local API)
36records = zot.items(format='json', include='data,bib', style='apa', limit=50)
37bib_entries = [record['bib'] for record in records]
38
39records = zot.items(format='json', include='citation', style='apa', limit=50)
40citations = [record['citation'] for record in records]
41```
42
43For one complete, style-sorted bibliography, use `format='bib'`. It has no sorting or pagination parameters and is limited to 150 matching items. In 1.15.2 its HTML response is returned as **bytes**, not a list of citation strings:
44
45```python
46html_bytes = zot.collection_items('COLKEY', format='bib', style='apa')
47html = html_bytes.decode('utf-8')
48```
49
50Pass a valid style identifier from the [Zotero style repository](https://www.zotero.org/styles), such as `apa`, `vancouver`, `ieee`, or `nature`; avoid assuming a renamed style alias still exists. `linkwrap='1'` wraps bibliography URLs in links.
51
52## RIS and Other Exports
53
54The [API format table](https://www.zotero.org/support/dev/web_api/v3/basics#export_formats) lists `ris`, `biblatex`, `rdf_dc`, `rdf_zotero`, `wikipedia`, and others. Pyzotero 1.15.2 dispatches by response content type. A live direct `format='ris'` response used `application/x-research-info-systems`, which the SDK tried to parse as JSON and failed. Use per-item JSON `include` instead:
55
56```python
57from pathlib import Path
58
59records = zot.everything(zot.items(format='json', include='ris', limit=50))
60Path('library.ris').write_text('\n'.join(r['ris'] for r in records), encoding='utf-8')
61```
62
63JSON records work with `everything()`. Direct exports may return a dict, bytes, or a BibDatabase depending on their content type; do not pass them all through one generic writer. Direct `biblatex` uses the BibTeX parser in this release. Export formats require a limit (except `bib`).
64
65Legacy `content='ris'`, `content='csljson'`, `content='bib'`, or `content='citation'` forces Atom and returns parsed lists in remote mode. If used, pass `content`, `style`, and `limit` on the **same** call. The local API does not support Atom. Prefer JSON `include` for per-item export data; unlike the SDK's legacy `content` parser, it supports multiple comma-separated members such as `include='data,bib'`.
66
67## Keys and Versions
68
69```python
70# Omit the SDK limit for these formats, which the remote API does not cap.
71keys_bytes = zot.items(format='keys', limit=None)
72keys = keys_bytes.decode('utf-8').splitlines()
73
74# Returns a dict, not a list; do not wrap it in everything().
75versions = zot.item_versions() # equivalent to items(format='versions', limit=None)
76```
77
78Source: [API response formats](https://www.zotero.org/support/dev/web_api/v3/basics#request_parameters), [release response dispatch](https://github.com/urschrei/pyzotero/blob/v1.15.2/src/pyzotero/_decorators.py).

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