
Ledger
CLI经典的纯文本复式记账命令行工具:账目写在文本文件里,直接生成余额、明细、预算等报表,没有数据库和隐藏状态,方便 agent 读写账本、对账和出报表。
Ledger: Command-Line Accounting
Ledger is a powerful, double-entry accounting system that is accessed from the UNIX command-line. This may put off some users, since there is no flashy UI, but for those who want unparalleled reporting access to their data there are few alternatives.
Ledger uses text files for input. It reads the files and generates reports; there is no other database or stored state. To use Ledger, you create a file of your account names and transactions, run from the command line with some options to specify input and requested reports, and get output. The output is generally plain text, though you could generate a graph or html instead. Ledger is simple in concept, surprisingly rich in ability, and easy to use.
For the Impatient
I know, you just want to build and play. If you have all the dependencies installed, then simply do this:
$ git clone git@github.com:ledger/ledger.git
$ cd ledger && ./acprep update # Update to the latest, configure, make
Now try your first ledger command:
$ ./ledger -f test/input/sample.dat reg
For help on keeping your journal have a look at the documentation, the wiki, and the Resources section at the end of this file. An Emacs mode for Ledger files can be found in the ledger/ledger-mode repository and a vim plugin is located in the ledger/vim-ledger repository.
Docker version
If you have Docker installed on your computer or server, you can use a Docker version of this software, without installing any further dependencies:
$ docker run --rm -v "$PWD"/test/input:/data dcycle/ledger:1 -f /data/sample.dat reg
Dependencies
If you wish to proceed in this venture, you'll need a few dependencies.
Note that some features, e.g. --import require building Ledger with Python support.
The easiest way to get them for your platform is to run this handy Python script:
$ ./acprep dependencies
If that doesn't completely work, here are the dependencies for building the
current main branch:
| Dependency | Version (or greater) |
|---|---|
| CMake | 3.16.2 |
| Boost | 1.72 |
| Gmp | 6.1.2 |
| Mpfr | 4.0.2 |
| utfcpp | 3.2.3 |
| ICU | 63 optional |
| gettext | 0.17 optional |
| libedit | 20090111-3.0 optional |
| Python | 3.10 optional |
| Gpgmepp | 1.13.1 optional |
| doxygen | 1.9.5 optional, for make docs |
| graphviz | 2.20.3 optional, for make docs |
| texinfo | 4.13 optional, for make docs |
| lcov | 1.6 optional, for make report, used with ./acprep gcov |
| sloccount | 2.26 optional, for make sloc |
macOS
You can use Homebrew or MacPorts to install build dependencies for Ledger easily on macOS.
1. Homebrew
If you use Homebrew, to install the dependencies you would run:
$ brew install cmake boost boost-python3 gmp mpfr
2. MacPorts
If you build stuff using MacPorts on macOS, as I do, here is what you would run:
$ sudo port install -f cmake python37 \
libiconv zlib gmp \
mpfr ncurses ncursesw \
gettext libedit boost-jam \
boost +st+python37+icu texlive doxygen graphviz \
texinfo lcov sloccount
Conda
The dependencies for building Ledger are available from conda-forge on certain
platforms (for example, linux-64), which can be used with Conda or mamba.
With Conda you could run:
$ conda install -c conda-forge python=3 cmake boost gmp mpfr \
gettext libedit texinfo doxygen graphviz
Ubuntu
If you're going to build on Ubuntu, sudo apt-get install ... the
following packages (current as of Ubuntu 18.04):
$ sudo apt-get install build-essential cmake doxygen \
libboost-system-dev libboost-dev python3-dev gettext git \
libboost-date-time-dev libboost-filesystem-dev \
libboost-iostreams-dev libboost-python-dev libboost-regex-dev \
libboost-test-dev libedit-dev libgmp3-dev libmpfr-dev texinfo tzdata
Debian
Debian 10 (bullseye), Debian 11 ("bullseye"), Debian testing and Debian unstable (sid) contain all components needed to build ledger. You can install all required build dependencies using the following command:
$ sudo apt-get install build-essential cmake autopoint texinfo python3-dev \
zlib1g-dev libbz2-dev libgmp3-dev gettext libmpfr-dev \
libboost-date-time-dev libboost-filesystem-dev \
libboost-graph-dev libboost-iostreams-dev \
libboost-python-dev libboost-regex-dev libboost-test-dev
Fedora
You can install all required build dependencies under Fedora using the following command (tested with Fedora 32):
$ sudo dnf install boost-date-time boost-devel boost-filesystem \
boost-iostreams boost-python3-devel boost-regex boost-system \
boost-test cmake doxygen gettext git gmp-devel libedit-devel \
mpfr-devel python3-devel texinfo tzdata
Building
The next step is preparing your environment for building. While you can use
cmake . and make, I've prepared a script that does a lot more of the
footwork for you:
$ ./acprep update
# or, if you want to use the Boost libraries with suffix -mt, install in
# $HOME/local and build with 2 processes in parallel
$ ./acprep update --boost-suffix=-mt --prefix=$HOME/local -j2
Please read the contents of CMakeFiles/CMakeOutput.log and
CMakeFiles/CMakeError.log if the configure step fails. Also,
see the help subcommand to acprep, which explains some of its many
options. It's pretty much the only command I run for configuring, building
and testing Ledger.
You can run make check to confirm the result, and make install to install.
Python Bindings
Ledger includes optional Python bindings built with Boost.Python. Python support is off by default and must be explicitly enabled.
Prerequisites
In addition to the standard dependencies, you need:
- Python 3.10 or later (with development headers)
- Boost.Python (matching your Boost and Python versions)
See the platform-specific dependency sections above for package names (e.g.
boost-python3 on Homebrew, libboost-python-dev on Ubuntu).
Building with Python Support
Using acprep:
$ ./acprep --python update --output=build
Or using CMake directly:
$ mkdir build && cd build
$ cmake -DUSE_PYTHON=ON ..
$ make -j$(nproc)
Installing the Python Module
Running make install (or cmake --install build) copies ledger.so (or
ledger.pyd on Windows) into your Python installation's site-packages
directory. After installing:
$ python -c "import ledger; print(ledger)"
Using Without Installing
To use the module directly from the build tree without installing, point
PYTHONPATH at the build directory:
$ PYTHONPATH=build python -c "import ledger; print(ledger)"
On Linux you may also need to set LD_LIBRARY_PATH=build, and on macOS
DYLD_LIBRARY_PATH=build.
A demo script is included at python/demo.py:
$ PYTHONPATH=build python python/demo.py
For full documentation of the Python API, see the "Extending with Python" chapter in the Ledger manual.
Resources
Now that you're up and running, here are a few resources to keep in mind:
- Homepage
- Documentation
- IRC channel: #ledger channel on Libera Chat
- Mailing List / Forum
- GitHub project page
- Code analysis
If you have ideas you'd like to share, the best way is either to e-mail me a patch (I prefer attachments over pasted text), or to get an account on GitHub. Once you do, fork the Ledger project, hack as much as you like, then open a pull request on GitHub.
相關資源

Beancount
CLI用文本文件记录复式记账交易的记账语言与工具集:bean-check 校验账本、bean-format 统一格式,配合 Fava、beanquery 出报表与查询;账本是纯文本,便于 agent 生成和版本管理。
beancount/beancount6.1k
hledger
CLI纯文本复式记账工具:记录收支、投资与工时,一条命令生成资产负债表、利润表与预算报表,支持 CSV 导入和 JSON 输出,便于 agent 对账出报表;可与 Beancount 账本互转。
hledgerorg/hledger4.8k
rustledger
CLIBeancount 纯文本复式记账的 Rust 实现,命令是 rledger:校验账本、跑 BQL 查询、出资产负债表与收支表,能导入银行 CSV/OFX 对账单、对比预算、计算投资收益和资本利得;另有 MCP 服务,GitHub 发行包还附带输出 JSON 的 ag-rledger,便于 agent 调用。账本需是 Beancount 格式,报表与涉税数字需会计复核。
rustledger/rustledger409
hledger-flow
CLIhledger 的自动记账流程工具:把银行、信用卡导出的 CSV 对账单按固定目录归档,套用分类规则一键生成账本,改规则后可重新生成,适合会计批量整理流水。需先安装 hledger,再从 Releases 页面下载程序(仅 macOS、Linux);账目结论需会计复核。
apauley/hledger-flow219
beanquery
CLIBeancount 官方账本查询工具 bean-query,用类 SQL 语句查询纯文本复式账本,出余额、收支分类汇总和账户明细,适合会计让 agent 核对账目、整理报表。需 uv 或 Python 3.8+ 和 Beancount 格式账本;报表结论需会计复核。
beancount/beanquery65
Norman MCP Server
MCP德国记账报税服务 Norman 的官方 MCP,让 agent 开发票(含 ZUGFeRD 电子发票)、分类流水、匹配收据、预览并提交增值税申报,并协助准备 GmbH/UG 注册材料。需注册 Norman 账号并用 OAuth 登录,主要面向德国业务;申报前需税务顾问复核。
norman-finance/norman-mcp-server61