Crates.io | anki_bridge |
lib.rs | anki_bridge |
version | 0.10.2 |
created_at | 2023-06-29 19:44:29.578725+00 |
updated_at | 2025-07-07 11:27:12.818523+00 |
description | AnkiBridge is a Rust library that provides a bridge between your Rust code and the Anki application, enabling HTTP communication and seamless data transmission. |
homepage | |
repository | https://gitlab.com/kerkmann/anki_bridge |
max_upload_size | |
id | 903615 |
size | 409,505 |
AnkiBridge is a Rust library that serves as a bridge between your Rust code and the Anki application, leveraging the AnkiConnect add-on to establish an HTTP connection. This library enables seamless transmission of data and facilitates interaction with Anki through Rust.
AnkiBridge provides the following features:
To use AnkiBridge in your Rust project, add the following line to your Cargo.toml
file:
[dependencies]
anki_bridge = { version = "0.10", features = ["ureq_blocking"] }
Additionally, ensure that you have the Anki application installed on your system and that the AnkiConnect add-on is installed within Anki.
Please note that Anki must be opened and running on your computer for AnkiBridge to establish a connection successfully.
To establish a connection and perform actions with Anki, you can utilize the functions and structs provided by the AnkiBridge library in your Rust code. Here's a basic example:
use anki_bridge::prelude::*;
fn main() {
// Creates a client to connect to the Anki instance running on the local computer
let anki = AnkiClient::default();
// Fetch the names of all the active decks
let decks = anki.request(DeckNamesRequest {}).unwrap();
dbg!(&decks);
// Fetch statistics about the decks above
let deck_stats = anki.request(GetDeckStatsRequest { decks }).unwrap();
dbg!(&deck_stats);
}
Please check the crate docs and the AnkiConnect docs to find all supported operations.
Check the following table for all the supported AnkiConnect actions.
use anki_bridge::{mock::*, prelude::*};
let client = MockAnkiClient::<FindCardsRequest, _>::new_mock(|params| {
Ok(vec![123, params.query.len()])
});
let response = client.request(FindCardsRequest {
query: "Card Deck Name".to_string(),
});
assert_eq!(
vec![123, "Card Deck Name".len()],
response.unwrap()
);
Contributions to AnkiBridge are welcome. Feel free to contribute by opening issues or submitting pull requests on the GitLab repository.
The entire changelog can be found in the CHANGELOG.md file.
Thanks to VaiTon for having the idea to just implement a trait, instead of writing a function. That helped me to write a mockable client and clean everything up. You can find his implementation of the AnkiConnect bridge on GitHub. :)
AnkiBridge is distributed under the MIT License. For more information, see the LICENSE file.
For any questions or inquiries, please contact the project maintainer at daniel@kerkmann.dev.