Skip to main content

A CLI tool to bi-directionally sync Anki notes as YAML files

Project description

Anki YAML Sync

A Python CLI tool for bi-directional syncing of Anki notes as YAML files for easy editing and version control.

Inspired by visserle/DeckOps.

Features

  • Bi-Directional Syncing: Import notes from Anki to YAML and export YAML back to Anki
  • Human-Readable Format: Notes are stored as YAML files for easy editing
  • Flexible: Update existing notes or create new notes (based on ID field)
  • Deck-Aware Storage: Notes are stored in folders that mirror deck nesting

Requirements

  • Anki: Running instance of Anki desktop
  • AnkiConnect: Must be installed and running on localhost:8765 (default)

To set up AnkiConnect (https://ankiweb.net/shared/info/2055492159):

  1. Open Anki > Menu Bar > Tools > Add-ons > Get Add-ons
  2. Enter the code 2055492159 and click "OK" to install AnkiConnect
  3. Restart Anki

Installation

Run the following command to install globally: pipx install anki-yaml-sync

Usage

Import Notes from Anki

Fetch all notes from Anki and save them as YAML files:

anki-yaml-sync import [--output-dir OUTPUT]

Aliases: get-from-anki, fetch, gfa, f

Options:

  • --output-dir, -o: Directory to save YAML files (default: notes)

Example:

anki-yaml-sync import --output-dir ./my-notes

Export Notes to Anki

Sync YAML files back to Anki:

anki-yaml-sync export [--input-dir INPUT] [--deck DECK]

Aliases: send-to-anki, push, sta, p

Options:

  • --input-dir, -i: Directory containing YAML files (default: notes)
  • --deck: Deck to add new notes to (default: Default)

Example:

anki-yaml-sync export --input-dir ./my-notes --deck "My Deck"

Verbose Output

Add -v or --verbose flag to any command for detailed logging:

anki-yaml-sync -v import
anki-yaml-sync -v export

YAML Format

Each note is stored as a separate YAML file. Example:

id: 1234567890
type: Basic
deck: Languages::French
tags:
  - french
  - vocabulary
fields:
  Front: Bonjour
  Back: Hello

Fields:

  • id: Anki note ID (required for updates)
  • type: Note type name (e.g., "Basic", "Cloze")
  • deck: Full deck name using :: (e.g., Parent::Child)
  • tags: List of tags to apply
  • fields: Dictionary of field names to field values
  • created: Creation timestamp
  • modified: LastModification timestamp

Deck Folder Structure

Deck nesting is reflected in folders. For example, a note in deck Languages::French is stored as:

notes/Languages/French/<note>.yaml

Workflow

  1. Initial Import: Run anki-yaml-sync import to create YAML files from your Anki collection
  2. Edit: Open and edit the YAML files with your text editor or IDE
  3. Sync Back: Run anki-yaml-sync export to sync your changes back to Anki

Updating Existing Notes

If a YAML file has an id field that matches an existing Anki note, the export will update that note. Fields are completely replaced (not merged).

If the YAML deck differs from the current deck, the note's cards will be moved to the YAML deck.

Creating New Notes

To create a new note:

  1. Create a new YAML file with a temporary or missing id (e.g., 0 or null)
  2. Run anki-yaml-sync export
  3. The YAML file will be automatically updated with the assigned note ID

Note: If the ID is that of an existing note, the existing note may be overwritten with the YAML file instead of creating a new note in Anki.

Contributing

See CONTRIBUTING.md for guidelines on contributing to this project and setting up development environment on your device.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

anki_yaml_sync-0.2.0.tar.gz (15.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

anki_yaml_sync-0.2.0-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file anki_yaml_sync-0.2.0.tar.gz.

File metadata

  • Download URL: anki_yaml_sync-0.2.0.tar.gz
  • Upload date:
  • Size: 15.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anki_yaml_sync-0.2.0.tar.gz
Algorithm Hash digest
SHA256 ba1e3282da6833d0b56f21dcd685a6cfbb608e5dca14c669a629f8600ac2069d
MD5 5fa4204e841bec11de2d95d9c08f4cd0
BLAKE2b-256 ccea2adbc04d11a1de06dde75f090e26166bf771bb5f50e14c750bbf9f44d2c7

See more details on using hashes here.

Provenance

The following attestation bundles were made for anki_yaml_sync-0.2.0.tar.gz:

Publisher: python-publish.yml on danielh-official/anki-yaml-sync

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file anki_yaml_sync-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: anki_yaml_sync-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for anki_yaml_sync-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 67b7bd4771d72a68f0801793e1306421ff43d545fc5f91068b506ec2d7c9bef3
MD5 47ef221c1714d6b3fc0c6e6a58bec21b
BLAKE2b-256 e047a0476bdbf9bd45360a932295d581b90f9adec357c8674c4d63a45c5a4f53

See more details on using hashes here.

Provenance

The following attestation bundles were made for anki_yaml_sync-0.2.0-py3-none-any.whl:

Publisher: python-publish.yml on danielh-official/anki-yaml-sync

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page