Libro:一款用于追踪你书籍的命令行工具
Libro: a command-line tool to track your books

原始链接: https://github.com/mkaz/libro

Libro是一个命令行工具,用于追踪你的阅读历史,数据本地存储在SQLite数据库中。你可以使用`libro add`添加书籍,使用`libro show --year`按年份查看书籍,或使用`libro show `查看指定ID的书籍详情。可以使用`libro report`生成按年份阅读书籍数量的报告,或使用`libro report --author`按作者生成报告。 数据库位置可以通过命令行参数、环境变量(`LIBRO_DB`)指定,或者默认存储在特定于平台的目录下。Libro可以导入Goodreads CSV导出数据。书籍分为“Fiction”(虚构类)和“Nonfiction”(非虚构类)两种类型,字段包括书名、作者、页数、出版年份、阅读日期、评分和评论。 你可以通过PyPI (`libro-book`)安装Libro,或者克隆代码库并在本地安装。打包使用hatchling工具。

Hacker News 用户正在讨论 Marcuskaz 创建的命令行工具“Libro”,它用于追踪阅读书籍并生成基本统计数据,使用 SQLite3 数据库和 Goodreads CSV 导入。 用户 9dev 表达了兴趣,提到了他们自己正在开发的开源电子书库“Colibri”,并可能从 Libro 获取灵感。candiddevmike 建议使用 Audiobookshelf 作为完整自托管的解决方案,用于有声读物和电子书,并强调了移动应用程序和用户帐户等功能。pyrophane 指出与有声读物销售商 Libro.fm 可能存在命名冲突。 marcuskaz 解释说 Libro 只是一个用于追踪阅读习惯的基本工具。benterix 询问了与 Cursor 一起使用的 LLM,推测可能是 Claude 3.7 或 Gemini 2.5。最后,shreyansdoshi 询问了对 Bookwyrm 导出的潜在支持。

原文

📚 Libro: A simple command-line tool to track your reading history, with your data stored locally in a SQLite database.

Add new book: libro add

Show books read by year: libro show --year 2024

Show book details by id: libro show 123

Show books read by year: libro report

Show books read by author: libro report --author

                                              Books Read in 2025
┏━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━┳━━━━━━━━━━━━━━┓
┃ id         ┃ Title                                           ┃ Author               ┃ Rating ┃ Date Read    ┃
┡━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━╇━━━━━━━━━━━━━━┩
│ Fiction    │                                                 │                      │        │              │
│ 1          │ Cujo                                            │ Stephen King         │ 3      │ Jan 05, 2025 │
│ 585        │ The Midnight Library                            │ Matt Haig            │ 5      │ Jan 13, 2025 │
│ 587        │ The Maid                                        │ Nita Prose           │ 4      │ Jan 20, 2025 │
│ 589        │ Into the Water                                  │ Paula Hawkins        │ 2      │ Feb 02, 2025 │
│ 591        │ My Grandmother Asked Me to Tell You She's Sorry │ Fredrik Backman      │ 3      │ Feb 15, 2025 │
│ 584        │ Salem's Lot                                     │ Stephen King         │ 3      │ Mar 12, 2025 │
│ 595        │ The Thursday Murder Club                        │ Richard Osman        │ 3.5    │ Mar 20, 2025 │
│ 596        │ Remarkably Bright Creatures                     │ Shelby Van Pelt      │ 5      │ Mar 27, 2025 │
│ 598        │ Colorless Tsukuru Tazaki                        │ Haruki Murakami      │ 3      │ Apr 09, 2025 │
│ 599        │ Ten                                             │ Gretchen McNeil      │ 3      │ Apr 16, 2025 │
│            │                                                 │                      │        │              │
│ Nonfiction │                                                 │                      │        │              │
│ 586        │ The Art Thief                                   │ Michael Finkel       │ 4      │ Jan 14, 2025 │
│ 588        │ All the Pieces Matter                           │ Jonathan Abrams      │ 3      │ Jan 27, 2025 │
│ 590        │ Supercommunicators                              │ Charles Duhigg       │ 4      │ Feb 04, 2025 │
│ 592        │ HBR Guide to Generative AI for Managers         │ Elisa Farri          │ 4      │ Feb 16, 2025 │
│ 593        │ Leonardo da Vinci                               │ Walter Isaacson      │ 3      │ Mar 02, 2025 │
│ 594        │ The Leap to Leader                              │ Adam Bryant          │ 3      │ Mar 08, 2025 │
│ 597        │ Team of Rivals                                  │ Doris Kearns Goodwin │ 3      │ Apr 06, 2025 │
└────────────┴─────────────────────────────────────────────────┴──────────────────────┴────────┴──────────────┘
❯ libro report

                         Books Read by Year

  Year   Count   Bar
 ───────────────────────────────────────────────────────────────────
  2013   3       ▄▄▄▄
  2014   4       ▄▄▄▄▄▄
  2015   11      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2016   30      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2017   21      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2018   27      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2019   29      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2020   27      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2021   28      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2022   27      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2023   32      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2024   30      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  2025   17      ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
❯ libro report --author

         Most Read Authors

  Author                Books Read
 ──────────────────────────────────
  Stephen King          15
  George R.R. Martin    5
  Timothy Zahn          4
  Grady Hendrix         4
  Andy Weir             4
  William Zinsser       3
  Roald Dahl            3
  Riley Sager           3
  Philip K. Dick        3
  Neil Gaiman           3
  Natalie D. Richards   3
  Lucy Foley            3
  Cory Doctorow         3

Libro is packaged as libro-book on PyPI.

You can also clone this repository and install it locally:

git clone https://github.com/mkaz/libro.git
cd libro
pip install -e .

On first run, libro will create a libro.db database file based on database location. It will prompt for confirmation to proceed which also shows the location where the file will be created.

Database locations:

The following order is used to determine the database location:

  1. Using the --db flag on command-line.

  2. libro.db in current directory

  3. Environment variable LIBRO_DB to specify custom file/location

  4. Finally, the user's platform-specific data directory

    • Linux: ~/.local/share/libro/libro.db
    • macOS: ~/Library/Application Support/libro/libro.db
    • Windows: %APPDATA%\libro\libro.db

For example, if you want to create a new database file in the current directory, you can use the following command:

Libro can import your reading history from a Goodreads export CSV file.

libro import goodreads_library_export.csv

There is a genre field for fiction and nonfiction, but this data is not available in the Goodreads export. I still need to build the edit book functionality to change the genre.

Field Type Description
id primary key Unique identifier
title string Book title
author string Book author
pages int Number of pages in book
pub_year int Year book was published
genre string Fiction or nonfiction
Field Type Description
id primary key Unique identifier
book_id foreign key Book identifier
date_read date Date book was read
rating float Number between 0 and 5
review text Review of book

Notes to self, I forget how to do this stuff.

Libro is packaged as libro-book on PyPI.

Packaging is done with hatchling, see Guide

# install tools
py -m pip install --upgrade build twine
# upload
py -m twine upload dist/*
联系我们 contact @ memedata.com