Skip to content

About

Typecho 博客 XML-RPC 客户端:封装 metaWeblog/wp 接口,支持文章、页面、分类、附件、评论的增删改查与批量发布

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

19 Commits

Folders and files

Repository files navigation

funtypecho

funtypecho 是 Typecho XML-RPC 客户端,提供文章、页面、分类、标签、附件和评论的 Python API,并支持把 Markdown/Notebook 批量发布到 Typecho。

安装

uv add funtypecho
uv add 'funtypecho[publish]'

最小示例

需要先有一个已开启 XML-RPC 的 Typecho 站点(后台「设置 - 常规 - 启用 XML-RPC 服务」),把下面的 URL、用户名、密码替换为该站点的实际值:

from funtypecho import Post, Typecho

client = Typecho("https://your-site.example.com/action/xmlrpc", "user", "password")
post_id = client.new_post(Post(title="你好", description="正文"), publish=False)
print(post_id)

RPC 失败会抛出带远端错误信息的 RuntimeError。

不依赖真实站点的本地示例

没有可用的 Typecho 站点时,可以用 unittest.mock 打桩 xmlrpc.client.ServerProxy,不访问网络也能在本地跑通调用链:

from types import SimpleNamespace
from unittest.mock import Mock

from funtypecho import Post, Typecho

client = Typecho("https://your-site.example.com/action/xmlrpc", "user", "password")
client.s = SimpleNamespace(metaWeblog=SimpleNamespace(newPost=Mock(return_value="1")))
post_id = client.new_post(Post(title="你好", description="正文"), publish=False)
print(post_id)  # "1"

开发

uv sync --extra publish
uv run pytest
uv run ruff check .
uv run ruff format --check .
uv run funbuild install

发布前先更新变更记录并确认版本递增符合预期,再执行 uv run funbuild build。该命令会依次完成版本递增、构建、产物安装校验、发布和 Git 标签;需要预先通过环境变量配置 PyPI 凭据。


关于 farfarfun

farfarfun 是一个专注于实用工具库的开源组织, 涵盖云存储、数据处理、AI、多媒体与开发工具链等方向。

本项目基于 MIT 协议开源。

About

Typecho 博客 XML-RPC 客户端:封装 metaWeblog/wp 接口,支持文章、页面、分类、附件、评论的增删改查与批量发布

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages