40万首中国古诗词,做成REST+GraphQL API开源了

400,000 Chinese Classical Poems, Packaged as a REST+GraphQL API

Tech-Experiment #开源工具#API#中文#古诗词#Go
🇨🇳 中文

40 万首古诗词,从诗经到清诗,一个 Go 写的 REST + GraphQL API 全打包了。

项目叫「诗泉」,作者 palemoky,GPL-3.0,目前 3.2K stars。数据来自 chinese-poetry/chinese-poetry 这个已有 50K stars 的社区诗词数据集(git 子模块引入)。

GitHub: https://github.com/palemoky/chinese-poetry-api | 在线演示: https://poetry.palemoky.com


收录规模

类型首数
七言绝句82,744
七言律诗68,696
五言律诗59,681
五言绝句16,860
宋词21,347
元曲10,904
乐府诗6,714
五代词543
诗经305
楚辞65
论语20
其余/未分类76,077+

总计约 40 万首,含作者、朝代、类型标注。


API:REST + GraphQL 双接口

REST base URL:http://<host>:1279/api/v1/

常用端点:

GET /poems                          # 分页列出诗词
GET /poems/search?q=静夜思          # 关键词搜索
GET /poems/random?author=李白&dynasty=唐&type=七言绝句  # 随机取诗(支持过滤)
GET /authors                        # 作者列表
GET /dynasties                      # 朝代列表
GET /types                          # 类型列表

GraphQL 路径:/graphql

支持三种搜索模式(searchType 参数):

query {
  searchPoems(query: "春眠", searchType: all) {
    title
    author
    content
  }
  statistics {
    total
    byDynasty { name count }
  }
}

searchType 可选:TITLE(标题)、content(全文)、author(作者)、all(全字段)。


简繁体切换

请求时带 lang 参数:

  • zh-Hans:简体中文(默认)
  • zh-Hant:繁体中文

转换由 gocc 完成,benchmark 约 300 ns/op,对 API 响应延迟影响可以忽略。


本地部署

Docker 一行起:

docker run -d -p 1279:1279 palemoky/chinese-poetry-api:latest

镜像支持 linux/amd64 和 linux/arm64(Apple Silicon 可直接跑)。默认端口 1279(取”诗”的部分谐音?),也可以通过 compose 改映射。

也可以直接 clone 源码编译:

git clone --recurse-submodules https://github.com/palemoky/chinese-poetry-api
cd chinese-poetry-api
go build .
./chinese-poetry-api

--recurse-submodules 必须带,数据在子模块里,不带拉不到诗词数据。


限速和边界

  • IP 限速:内置,具体阈值文档未标注,生产用建议在前面挂反代加额外限速
  • 只读:纯查询 API,没有写入接口
  • 无认证:本地或内网部署不需要 API key;公网暴露需自己加认证层
  • LICENSE:GPL-3.0——商用嵌入需注意,内容展示类用途(网站、App)要评估是否触发 copyleft

数据来源的溯源

诗词数据引用自 chinese-poetry/chinese-poetry(50.2K stars,CC 协议,已整理超 80 万首),这个数据集本身也是社区多年维护的成果,诗泉在它上面建了查询层。


一句话说清楚

chinese-poetry-api 是一个 Go 写的古诗词查询服务:40 万首,REST + GraphQL 双接口,简繁体切换,Docker 多架构支持,GPL-3.0。在线试用:https://poetry.palemoky.com


GPL-3.0。palemoky,2025-12-08 创建,数据源:chinese-poetry/chinese-poetry。开源仅供学习参考。


🇬🇧 English

400,000 Chinese Classical Poems, Packaged as a REST+GraphQL API

400,000 classical Chinese poems — from Shijing to Qing dynasty verse — wrapped in a Go-written REST + GraphQL API.

The project is called Shiquan (诗泉, “Poetry Spring”), by palemoky. GPL-3.0, 3.2K stars. Poem data comes from the chinese-poetry/chinese-poetry community dataset (50K+ stars), brought in as a git submodule.

GitHub: https://github.com/palemoky/chinese-poetry-api | Live demo: https://poetry.palemoky.com


Collection Size

TypeCount
7-character jueju82,744
7-character lüshi68,696
5-character lüshi59,681
5-character jueju16,860
Song ci21,347
Yuan qu10,904
Yuefu6,714
Five Dynasties ci543
Shijing305
Chuci65
Analects (Lunyu)20
Other/unclassified76,077+

Total: approximately 400,000 poems, with author, dynasty, and type annotations.


API: REST + GraphQL Dual Interface

REST base URL: http://<host>:1279/api/v1/

Common endpoints:

GET /poems                          # paginated listing
GET /poems/search?q=静夜思          # keyword search
GET /poems/random?author=李白&dynasty=唐&type=七言绝句  # random poem (with filters)
GET /authors                        # author list
GET /dynasties                      # dynasty list
GET /types                          # type list

GraphQL path: /graphql

Three search modes via searchType:

query {
  searchPoems(query: "spring", searchType: all) {
    title
    author
    content
  }
  statistics {
    total
    byDynasty { name count }
  }
}

searchType options: TITLE, content, author, all.


Simplified/Traditional Conversion

Pass a lang parameter:

  • zh-Hans: Simplified Chinese (default)
  • zh-Hant: Traditional Chinese

Conversion uses gocc, benchmarked at ~300 ns/op — negligible API latency impact.


Local Deployment

One-line Docker start:

docker run -d -p 1279:1279 palemoky/chinese-poetry-api:latest

Multi-arch image: linux/amd64 and linux/arm64 (Apple Silicon works natively).

Or build from source:

git clone --recurse-submodules https://github.com/palemoky/chinese-poetry-api
cd chinese-poetry-api
go build .
./chinese-poetry-api

--recurse-submodules is required — poem data lives in the submodule.


Limits and Boundaries

  • IP rate limiting: built-in; specific thresholds undocumented — add a reverse proxy for production
  • Read-only: query-only API, no write endpoints
  • No authentication: no API key needed for local/internal use; add an auth layer before public exposure
  • GPL-3.0: commercial embedding requires evaluation; display-only use cases (websites, apps) should assess copyleft implications

TL;DR

chinese-poetry-api is a Go-based classical Chinese poetry query service: 400,000 poems, REST + GraphQL, simplified/traditional conversion, multi-arch Docker, GPL-3.0. Try it: https://poetry.palemoky.com


GPL-3.0. palemoky, created 2025-12-08. Data source: chinese-poetry/chinese-poetry. For reference only.

💬 评论与讨论

使用 GitHub 账号登录后发表评论

关于本站 · 免责声明

🍄 Mushroom Research Blog 是非营利、免费公开的个人科技观察博客与公众号 XStack18,不接受商业合作、不代表任何企业或机构立场,也不谋求商业利益。我们以个人视角客观中立地记录和分析 AI、Web3 等领域的最新模型发布与技术动态——不止转述新闻标题或二手信息,而是给出有独立思考的深入分析,希望帮更多人获得有价值的一手科技认知。

⚠️ 文中介绍的开源代码与模型,仅供学习交流与技术借鉴。它们大多仍处于早期阶段,有待进一步研究和验证,请勿直接用于工作或生产环境;如需采用,请先自行充分测试,并核实其许可证与安全性。
Open-source code and models featured here are shared for learning and reference only. Most are early-stage and still need further study and verification — please don't use them directly in your work or in production. Test them thoroughly and check their licenses and security first.

  1. 本站文章均为作者基于公开信息的个人研究与观点整理,不代表文中提及的任何公司、产品、模型的官方立场,未与其构成商业关联或合作关系。
  2. 科技行业信息更新极快,我们尽力保证内容准确、及时,但不对完整性、实时性做绝对保证,具体请以相关企业/项目官方公告为准。
  3. 文中引用的第三方商标、产品名称、图片、数据等版权归原权利人所有,我们会尽量注明来源;如你认为存在版权疑问或侵权,请通过下方邮箱联系我们,收到通知后会尽快核实处理(更正、加注来源或删除)。
  4. 文章内容仅为技术科普与个人观点,不构成投资、法律或其他专业建议,据此进行任何决策的后果需自行判断和承担。

📮 侵权 / 勘误 / 合作咨询:[email protected]