ankiconnect-rs
A work-in-progress Rust crate for interacting with AnkiConnect, enabling convenient programmatic control of Anki from within Rust applications. Provides type-safe abstractions for common Anki operations with a clean domain-driven API.
Features
- 🃏 Card Management: Create notes, find cards, browse cards via the Anki GUI
- 🗃️ Deck Operations: Create decks, list existing decks, get statistics
- 📦 Media Handling: Store media files from paths/URLs/base64 data
- 🧩 Model Support: Work with note types, validate fields, manage templates
- 🔍 Search Capabilities: Build complex search queries with a fluent interface
- 🔄 Error Handling: Comprehensive error types for AnkiConnect-specific issues
- ✅ Well Tested: Mock server integration tests for all major operations
Installation
Add this to your Cargo.toml:
[]
= "1.0.0"
Prerequisites
- Anki with AnkiConnect installed
- Anki running with AnkiConnect enabled (default:
localhost:8765)
API Overview
The crate is organized around a central AnkiClient that provides access to domain-specific clients:
client.cards()- Operations for notes and cards (add notes, find cards, etc.)client.decks()- Operations for decks (create, list, get stats, etc.)client.models()- Operations for note types (get fields, templates, etc.)client.media()- Operations for media files (store, retrieve, etc.)
Usage
Basic Example
use ;
use Error;
Adding Media to Notes
use ;
use Error;
Building Search Queries
use ;
use Error;
More Examples
See the examples directory for more complete examples:
list_decks.rs- Listing decks and their informationlist_models.rs- Listing models (note types) and their fieldsadd_note.rs- Interactive example of adding a note with media
License
Licensed under either of:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contributing
Contributions welcome! Please feel free to submit a Pull Request.