A CLI tool to import/export 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.
Features
- Import: Fetch all notes from Anki and save them as YAML files
- Export: Sync edited YAML files back to Anki
- Flexible: Update existing notes or create new ones
- Simple: Flat file structure, one YAML file per note
Installation
Requirements
- Python 3.8+
- Anki with AnkiConnect installed
Setup
- Fork and clone the repository:
git clone <repo-url>
cd anki-yaml-sync
- Install the package in development mode:
pip install -e .
This will install the CLI tool anki-yaml-sync and all dependencies.
Development Installation
To install with development dependencies (for testing and linting):
pip install -e ".[dev]"
Usage
Import Notes from Anki
Fetch all notes from Anki and save them as YAML files:
anki-yaml-sync import [--output-dir OUTPUT]
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]
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
tags:
- french
- vocabulary
fields:
Front: Bonjour
Back: Hello
created: 2024-02-12T10:30:00
modified: 2024-02-12T10:30:00
Fields:
id: Anki note ID (required for updates)type: Note type name (e.g., "Basic", "Cloze")tags: List of tags to applyfields: Dictionary of field names to field valuescreated: Creation timestampmodified: LastModification timestamp
Workflow
- Initial Import: Run
anki-yaml-sync importto create YAML files from your Anki collection - Edit: Open and edit the YAML files with your text editor or IDE
- Sync Back: Run
anki-yaml-sync exportto 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).
Creating New Notes
To create a new card:
- Create a new YAML file with a temporary or missing
id(e.g.,0ornull) - Run
anki-yaml-sync export - The YAML file will be automatically updated with the assigned note ID
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):
- Open Anki > Menu Bar > Tools > Add-ons > Get Add-ons
- Enter the code
2055492159and click "OK" to install AnkiConnect - Restart Anki
Testing
Run tests with pytest:
source venv/bin/activate && pytest
With coverage:
source venv/bin/activate && pytest --cov=anki_sync
Troubleshooting
"Could not connect to Anki Connect"
- Ensure Anki is running
- Verify AnkiConnect is installed (Tools → Add-ons in Anki)
- Check that AnkiConnect is listening on
localhost:8765
"Model not found"
- Ensure the note type (model) name matches exactly in Anki
- Check spelling and capitalization
YAML parsing errors
- Ensure YAML syntax is valid
- Use proper indentation (spaces, not tabs)
- Quote special characters in strings if needed
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anki_yaml_sync-0.1.0.tar.gz.
File metadata
- Download URL: anki_yaml_sync-0.1.0.tar.gz
- Upload date:
- Size: 13.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
853fdfe794786d6e0a3b7ec8b83a95da29c654fe6fdfb16d516cd59b8b5cf2bc
|
|
| MD5 |
ed6dbf7c072cab62739802a455be96be
|
|
| BLAKE2b-256 |
b04c68b669aa039f07fea4bd172986433541a772fbd470390962605ee30ddcf7
|
File details
Details for the file anki_yaml_sync-0.1.0-py3-none-any.whl.
File metadata
- Download URL: anki_yaml_sync-0.1.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f7d9a55fd852af1d71fbcd1461a9aab1b55d4a751a3db7b882db9ac91010eb83
|
|
| MD5 |
1aedfdaa9f7e8840b9d2c44f00350342
|
|
| BLAKE2b-256 |
cdb20085f6f0353f73ca1b2355fe4d80dbed226f9d803fbc7b635fe5994bfab2
|