Skip to main content

A small CLI for reading and writing notes in a local Obsidian vault.

Project description

odcli

一个基于 Python 的本地 CLI,用来对 Obsidian vault 做读写操作。它直接操作 vault 里的 Markdown 文件,不依赖 Obsidian 的私有接口,因此稳定、可移植,也方便后续扩展。

功能

  • 校验 vault 路径是否有效
  • 列出 vault 中的 Markdown 笔记
  • 读取指定笔记
  • 按指定行区间读取笔记
  • 覆盖写入或自动创建笔记
  • 按指定行区间覆盖写入
  • 追加内容到笔记末尾
  • 在 vault 中全文搜索

使用 uv

cd /Users/huchang/agents/obsidian_cli
uv sync
uv run obsidian-cli --help

运行测试:

cd /Users/huchang/agents/obsidian_cli
uv run python -m unittest discover -s tests

构建分发包:

cd /Users/huchang/agents/obsidian_cli
uv build

发布到 PyPI 后,安装包名会是 odcli

直接运行

cd /Users/huchang/agents/obsidian_cli
./obsidian-cli --help

如果你更喜欢显式调用 Python:

PYTHONPATH=src python3 -m obsidian_cli --help

可选安装

如果你想安装到虚拟环境中:

cd /Users/huchang/agents/obsidian_cli
uv sync

指定 vault

优先级如下:

  1. --vault /path/to/vault
  2. 环境变量 OBSIDIAN_VAULT

示例:

export OBSIDIAN_VAULT="/Users/your-name/Documents/MyVault"
./obsidian-cli check
./obsidian-cli list
./obsidian-cli read Inbox/today.md
./obsidian-cli read-lines Inbox/today.md 3 8
./obsidian-cli write Inbox/today.md --content "# Today"
./obsidian-cli write-lines Inbox/today.md 3 4 --content "- replaced\n- lines\n"
./obsidian-cli append Inbox/today.md --content "\n- new item"
./obsidian-cli search "project alpha"

命令

check

检查 vault 是否存在,以及是否包含 .obsidian 目录。

list

列出 vault 中的 Markdown 文件。

可选参数:

  • --limit N

read

读取笔记内容。

参数:

  • note_path:相对于 vault 根目录的路径

write

覆盖写入笔记;若父目录不存在会自动创建。

参数:

  • note_path
  • --content TEXT
  • --stdin:从标准输入读取内容

可选参数:

  • --create-only:若文件已存在则报错

read-lines

读取指定行区间,行号从 1 开始,区间是闭区间。

参数:

  • note_path
  • start_line
  • end_line

write-lines

用新内容替换指定行区间,行号从 1 开始,区间是闭区间。

参数:

  • note_path
  • start_line
  • end_line
  • --content TEXT
  • --stdin

append

追加内容到笔记末尾。

参数:

  • note_path
  • --content TEXT
  • --stdin

search

在所有 Markdown 笔记中搜索文本。

参数:

  • query
  • --case-sensitive

测试

cd /Users/huchang/agents/obsidian_cli
uv run python -m unittest discover -s tests

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

odcli-0.1.0.tar.gz (8.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

odcli-0.1.0-py3-none-any.whl (6.4 kB view details)

Uploaded Python 3

File details

Details for the file odcli-0.1.0.tar.gz.

File metadata

  • Download URL: odcli-0.1.0.tar.gz
  • Upload date:
  • Size: 8.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for odcli-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5a88f624446e8baa4fe028faaafcb812e16bbdcc699742c2e7291edbeb4bda2f
MD5 3664d514a25d2aaa229474cb8a1fc29a
BLAKE2b-256 1e9980c42f9dcb502a0e9fc189a68a1075b3c9c2259e672ab08a55853a761fdd

See more details on using hashes here.

File details

Details for the file odcli-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: odcli-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 6.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.9

File hashes

Hashes for odcli-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a42882c1c22192463cc212e83feb938fe1c32742905927fde2898101fc44e818
MD5 33f03799a661eb4553ff6a5c067669d6
BLAKE2b-256 804ff0ba446e41660412c6b0795784b84392a0c739c67be9805bef6fa403e203

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page