anki_bridge

Crates.ioanki_bridge
lib.rsanki_bridge
version0.10.2
created_at2023-06-29 19:44:29.578725+00
updated_at2025-07-07 11:27:12.818523+00
descriptionAnkiBridge is a Rust library that provides a bridge between your Rust code and the Anki application, enabling HTTP communication and seamless data transmission.
homepage
repositoryhttps://gitlab.com/kerkmann/anki_bridge
max_upload_size
id903615
size409,505
DaniƩl Kerkmann (kerkmann)

documentation

https://docs.rs/anki_bridge

README

AnkiBridge

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.

Features

AnkiBridge provides the following features:

  • Establishing a connection with Anki through the AnkiConnect add-on.
  • Sending requests to Anki for various actions.
  • Retrieving data and statistics from Anki.
  • Interacting with cards and decks in Anki.

Installation

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.

Usage

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.

Category Requests
Card AnswerCardsRequestAreDueRequestAreSuspendedRequestCardsInfoRequestCardsModTimeRequestCardsToNotesRequestFindCardsRequestForgetCardsRequestGetEaseFactorsRequestGetIntervalsRequestGetIntervalsAlternativeRequestRelearnCardsRequestSetDueDateRequestSetEaseFactorsRequestSetSpecificValueOfCardRequestSuspendRequestSuspendedRequestUnsuspendRequest
Deck ChangeDeckRequestCloneDeckConfigIdRequestCreateDeckRequestDeckNamesAndIdsRequestDeckNamesRequestDeleteDecksRequestGetDeckConfigRequestGetDeckStatsRequestGetDecksRequestRemoveDeckConfigIdRequestSaveDeckConfigRequestSetDeckConfigIdRequest
Graphical GuiAddCardsRequestGuiAnswerCardRequestGuiBrowseRequestGuiCheckDatabaseRequestGuiCurrentCardRequestGuiDeckBrowserRequestGuiDeckOverviewRequestGuiDeckReviewRequestGuiEditNoteRequestGuiExitAnkiRequestGuiImportFileRequestGuiSelectCardRequestGuiSelectedNotesRequestGuiShowAnswerRequestpub struct GuiShowQuestionRequest;GuiStartCardTimerRequestGuiUndoRequest
Media DeleteMediaFileRequestGetMediaDirPathRequestGetMediaFilesNamesRequestRetrieveMediaFileRequestStoreMediaFileRequest
Miscellaneous ApiReflectRequestExportPackageRequestGetActiveProfileRequestGetProfilesRequestImportPackageRequestLoadProfileRequestMultiRequestReloadCollectionsRequestRequestPermissionRequestSyncRequestVersionRequest
Model CreateModelRequestFindAndReplaceInModelsRequestFindModelsByIdRequestFindModelsByNameRequestModelFieldAddRequestModelFieldDescriptionsRequestModelFieldFontsRequestModelFieldNamesRequestModelFieldRemoveRequestModelFieldRenameRequestModelFieldRepositionRequestModelFieldSetDescriptionRequestModelFieldSetFontRequestModelFieldSetFontSizeRequestModelFieldsOnTemplatesRequestModelNamesRequestModelNamesAndIdsRequestModelStylingRequestModelTemplateAddRequestModelTemplateRemoveRequestModelTemplateRenameRequestModelTemplateRepositionRequestModelTemplatesRequestUpdateModelStylingRequestUpdateModelTemplatesRequest
Note AddNoteRequestAddNotesRequestAddTagsRequestCanAddNotesRequestCanAddNotesWithErrorDetailRequestClearUnusedTagsRequestDeleteNotesRequestFindNotesRequestGetNoteTagsRequestGetTagsRequestNotesInfoRequestNotesModTimeRequestRemoveEmptyNotesRequestRemoveTagsRequestReplaceTagsRequestReplaceTagsInAllNotesRequestUpdateNoteRequestUpdateNoteFieldsRequestUpdateNoteModelRequestUpdateNoteTagsRequest
Statistic CardReviewsRequestGetCollectionStatsHTMLRequestGetLatestReviewIDRequestGetNumCardsReviewedByDayRequestGetNumCardsReviewedTodayRequestGetReviewsOfCardsRequestInsertReviewsRequest

Mocking Data

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()
);

Contributing

Contributions to AnkiBridge are welcome. Feel free to contribute by opening issues or submitting pull requests on the GitLab repository.

Changelog

The entire changelog can be found in the CHANGELOG.md file.

Special Thanks

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. :)

License

AnkiBridge is distributed under the MIT License. For more information, see the LICENSE file.

Contact

For any questions or inquiries, please contact the project maintainer at daniel@kerkmann.dev.

Commit count: 67

cargo fmt