references/cli.md
3.7 KB查看排版效果| 1 | # Command-Line Interface |
| 2 | |
| 3 | The pyzotero CLI connects to your **local Zotero installation** (Zotero 7+ for reads, Zotero 10+ for writes) (not the remote Web API). It requires a running Zotero desktop app with local API access enabled: |
| 4 | |
| 5 | **Zotero → Settings → Advanced → Allow other applications on this computer to communicate with Zotero** |
| 6 | |
| 7 | ## Installation |
| 8 | |
| 9 | ```bash |
| 10 | uv add "pyzotero[cli]==1.15.2" |
| 11 | # or run without installing: |
| 12 | uvx --from "pyzotero[cli]==1.15.2" pyzotero search -q "your query" |
| 13 | ``` |
| 14 | |
| 15 | ## Searching |
| 16 | |
| 17 | ```bash |
| 18 | # Search titles and metadata |
| 19 | pyzotero search -q "machine learning" |
| 20 | |
| 21 | # Full-text search (includes PDF content) |
| 22 | pyzotero search -q "climate change" --fulltext |
| 23 | |
| 24 | # Filter by item type |
| 25 | pyzotero search -q "methodology" --itemtype journalArticle --itemtype book |
| 26 | |
| 27 | # Filter by tags (AND logic) |
| 28 | pyzotero search -q "evolution" --tag "reviewed" --tag "high-priority" |
| 29 | |
| 30 | # Search within a collection |
| 31 | pyzotero search --collection ABC123 -q "test" |
| 32 | |
| 33 | # Paginate results |
| 34 | pyzotero search -q "deep learning" --limit 20 --offset 40 |
| 35 | |
| 36 | # Output as JSON (for machine processing) |
| 37 | pyzotero search -q "protein" --json |
| 38 | ``` |
| 39 | |
| 40 | ## Getting Individual Items |
| 41 | |
| 42 | ```bash |
| 43 | # Get a single item by key |
| 44 | pyzotero item ABC123 |
| 45 | |
| 46 | # Get as JSON |
| 47 | pyzotero item ABC123 --json |
| 48 | |
| 49 | # Get child items (attachments, notes) |
| 50 | pyzotero children ABC123 --json |
| 51 | |
| 52 | # Get multiple items at once (up to 50) |
| 53 | pyzotero subset ABC123 DEF456 GHI789 --json |
| 54 | ``` |
| 55 | |
| 56 | ## Collections & Tags |
| 57 | |
| 58 | ```bash |
| 59 | # List all collections |
| 60 | pyzotero listcollections |
| 61 | |
| 62 | # List all tags |
| 63 | pyzotero tags |
| 64 | |
| 65 | # Tags in a specific collection |
| 66 | pyzotero tags --collection ABC123 |
| 67 | ``` |
| 68 | |
| 69 | ## Full-Text Content |
| 70 | |
| 71 | ```bash |
| 72 | # Get full-text content of an attachment |
| 73 | pyzotero fulltext ABC123 |
| 74 | ``` |
| 75 | |
| 76 | ## Item Types |
| 77 | |
| 78 | ```bash |
| 79 | # List all available item types |
| 80 | pyzotero itemtypes |
| 81 | ``` |
| 82 | |
| 83 | ## DOI Index |
| 84 | |
| 85 | ```bash |
| 86 | # Get complete DOI-to-key mapping (useful for caching) |
| 87 | pyzotero doiindex > doi_cache.json |
| 88 | # Returns JSON: {"10.1038/s41592-024-02233-6": {"key": "ABC123", "doi": "..."}} |
| 89 | ``` |
| 90 | |
| 91 | ## Output Format |
| 92 | |
| 93 | By default the CLI outputs human-readable text including title, authors, date, publication, volume, issue, DOI, URL, and PDF attachment paths. |
| 94 | |
| 95 | Use `--json` for structured JSON output suitable for piping to other tools. |
| 96 | |
| 97 | ## Search Behaviour Notes |
| 98 | |
| 99 | - Default search covers top-level item titles and metadata fields only |
| 100 | - `--fulltext` expands search to PDF content; results show parent bibliographic items (not raw attachments) |
| 101 | - Multiple `--tag` flags use AND logic |
| 102 | - Multiple `--itemtype` flags use OR logic |
| 103 | |
| 104 | ## Authorized Local Writes (Zotero 10+) |
| 105 | |
| 106 | The CLI also supports local writes in the reviewed 1.15.2 release. These are illustrative commands, not part of the read-only smoke test: |
| 107 | |
| 108 | ```bash |
| 109 | # Zotero displays its authorization dialog; choose the scope you intend. |
| 110 | pyzotero authorize --app-name "Research library tool" |
| 111 | pyzotero listitemfields journalArticle |
| 112 | pyzotero createitem items.json --json |
| 113 | pyzotero createcollection "Review papers" --json |
| 114 | pyzotero addtocollection COLKEY ITEMKEY --json |
| 115 | pyzotero removefromcollection COLKEY ITEMKEY --json |
| 116 | pyzotero movetocollection --from OLDCOLKEY --to NEWCOLKEY ITEMKEY --json |
| 117 | ``` |
| 118 | |
| 119 | `items.json` contains an editable item object or array of objects. Validate bibliographic metadata before importing. The stored persistent local key and server ID are in `$XDG_CONFIG_HOME/pyzotero/local-api-key.json` (default `~/.config/pyzotero/local-api-key.json`); a Web API key does not authorize these commands. Collection membership commands update one item at a time. |
| 120 | |
| 121 | For Semantic Scholar CLI commands (`related`, `citations`, `references`, `s2search`), network access is required; see the limitations in [mcp.md](mcp.md). Sources: [CLI documentation](https://pyzotero.readthedocs.io/en/latest/#command-line-interface), [release CLI source](https://github.com/urschrei/pyzotero/blob/v1.15.2/src/pyzotero/cli.py). |
文件内容是平台检查时读出的文本,只供查看。平台不会运行包里的任何脚本或程序。

