gnucash-sys
Rust FFI bindings and safe wrappers for the GnuCash accounting engine.
Overview
This workspace provides Rust access to GnuCash's core accounting functionality:
- gnucash-sys - FFI bindings and safe wrappers for core types (Book, Account, Transaction, Split)
- gnucash-ext - Extended functionality (business entities, queries, builders)
Features
- Safe Rust wrappers around GnuCash C API
- Full access to accounts, transactions, splits, and balances
- Session management for opening/creating GnuCash files
- Business entities (Customer, Vendor, Invoice, etc.)
- Query framework for searching
- Builder patterns for complex entity creation
- Compatible with docs.rs (pre-generated bindings)
Requirements
System Dependencies
Install GnuCash development libraries:
Debian/Ubuntu:
Fedora:
Arch Linux:
macOS (Homebrew):
Rust
Rust 2024 edition (1.85+) is required.
Building
Using System Libraries (Recommended)
The build script automatically detects GnuCash using pkg-config:
# Clone the repository
# Build
# Run tests
# Build examples
Custom Library Paths
If GnuCash is installed in a non-standard location, set environment variables:
# Using .env file
# Or export directly
Build Configuration
The build script searches for libraries in this order:
- Environment variables (
GNUCASH_LIB,GNUCASH_INCLUDE) - pkg-config (
gnucash,gnucash-engine) - Common system paths (
/usr/lib/gnucash,/usr/include/gnucash)
Quick Start
use ;
Opening Existing Files
use ;
Workspace Structure
gnucash-sys/
├── src/ # Core FFI bindings and wrappers
│ ├── lib.rs # Main library entry
│ ├── book.rs # Book wrapper
│ ├── account.rs # Account wrapper
│ ├── transaction.rs # Transaction wrapper
│ ├── split.rs # Split wrapper
│ ├── session.rs # Session management
│ ├── price.rs # Price database
│ ├── types.rs # Guid, Numeric types
│ └── ...
├── examples/ # Example programs
├── docs/
│ └── API.md # Core API documentation
├── app/ # gnucash-ext crate
│ ├── src/
│ │ ├── lib.rs # Extended library
│ │ ├── business/ # Business entities
│ │ ├── query.rs # Query framework
│ │ ├── builder.rs # Builder patterns
│ │ └── ...
│ ├── examples/ # Business examples
│ ├── docs/
│ │ └── API.md # Extended API documentation
│ └── README.md
├── Cargo.toml # Workspace configuration
├── build.rs # Build script for bindgen
└── README.md # This file
Documentation
API Reference
- gnucash-sys API - Core types (Book, Account, Transaction, Split, Session)
- gnucash-ext API - Extended types (Customer, Vendor, Invoice, Query, Builder)
Examples
- Core Examples - Examples using gnucash-sys
- Business Examples - Examples using gnucash-ext
Running Examples
# List available examples
# Core examples
# Business examples (gnucash-ext)
Core Types
| Type | Description |
|---|---|
Session |
Connection to GnuCash file/database |
Book |
Top-level container for financial data |
Account |
Ledger in hierarchical tree |
Transaction |
Double-entry accounting record |
Split |
Single entry linking amount to account |
Guid |
128-bit unique identifier |
Numeric |
Rational number for precise arithmetic |
Price |
Price quote for commodity |
PriceDB |
Database of prices |
Extended Types (gnucash-ext)
| Type | Description |
|---|---|
Customer |
Customer for invoicing |
Vendor |
Vendor/supplier |
Employee |
Employee for expense vouchers |
Job |
Project linked to customer |
Invoice |
Invoice, bill, or voucher |
Entry |
Line item in invoice |
Owner |
Polymorphic owner type |
Query |
QofQuery for searching |
TransactionBuilder |
Fluent transaction creation |
InvoiceBuilder |
Fluent invoice creation |
Safety
The safe wrappers handle memory management via RAII (Drop trait). Key patterns:
- Edit cycle: Call
begin_edit()before modifications,commit_edit()after - Ownership: Use
mark_unowned()after adding entities to hierarchies - Sessions: Always call
session.end()when done
Note: The underlying GnuCash library is not thread-safe. While wrapper types implement Send, concurrent access requires external synchronization.
License
MIT
Contributing
Contributions welcome! Please ensure:
- Code builds without warnings
- Examples compile and run
- Documentation is updated for API changes
Related Projects
- GnuCash - The GnuCash accounting software
- GnuCash Source - GnuCash source code