-
Notifications
You must be signed in to change notification settings - Fork 195
Home
Script to add flashcards from a text or markdown file to Anki. Run from the command line. Built with Obsidian markdown syntax in mind. Supports user-defined custom syntax for flashcards.
See the Trello for planned features.
Current features:
- Custom note types - You're not limited to the 6 built-in note types of Anki.
- Updating notes from file - Your text files are the canonical source of the notes.
- Tags, including tags for an entire file.
- Adding to user-specified decks, on a per-file basis.
- Markdown formatting, including math formatting
- Embedded images. GIFs should work too.
- Audio.
- Auto-deleting notes from the file.
- Reading from all files in a directory automatically - recursively too!
- Inline Notes - Shorter syntax for typing out notes on a single line.
- Easy cloze formatting - A more compact syntax to do Cloze text
- Obsidian integration - Currently, this only includes a link to the file that made the flashcard, appended to the first field of your card.
-
Custom syntax - Using regular expressions, add custom syntax to generate notes that make sense for you. Some examples:
-
RemNote single-line style.
This is how to use::Remnote single-line style
- Header paragraph style.
# Style This style is suitable for having the header as the front, and the answer as the back
Q: How do you use this style? A: Just like this.
In Neuracache style, to make a flashcard you do #flashcard The next lines then become the back of the flashcard
How do you use ruled style? --- You need at least three '-' between the front and back of the card.
| Why might this style be useful? | | ------ | | It looks nice when rendered as HTML in a markdown editor. |
The idea of {cloze paragraph style} is to be able to recognise any paragraphs that contain {cloze deletions}.
-
RemNote single-line style.
Note that all custom syntax is off by default, and must be programmed into the script via the config file - see Custom syntax for instructions.
It might be useful to show the motivation for me personally writing the script in the first place.
My workflow is essentially to have notes be flashcards - one of my notes (before I discovered Obsidian). However, it got tedious to keep copy-pasting cards into Anki, so I got the idea to write a script to do it automatically.
However, you don't need to have your notes be files of flashcards to use this script! You just need to be fine with visibly embedding flashcards in your notes, and keeping them there for future reference/editing. The script will ignore anything it doesn't think is a flashcard, so you're free to add context/information not needed for Anki to your notes.
- Install the latest version of Python.
- Start up Anki, and navigate to your desired profile.
- Ensure that you've installed AnkiConnect.
- If you are a new user, download
obstoanki_setup.pyfrom the releases page, and place it in the folder you want the script installed (for example your notes folder). - Run
obstoanki_setup.py, for example by double-clicking it in a file explorer. This will download the latest version of the script and required dependencies automatically. Existing users should be able to run their existingobstoanki_setup.pyto get the latest version of the script. - Check the Permissions tab below to ensure the script is able to run.
- Run
obsidian_to_anki.py, for example by double-clicking it in a file explorer. This will generate a config file,obsidian_to_anki_config.ini.
See Troubleshooting if you have problems.
The script needs to be able to:
- Make a config file in the directory the script is installed.
- Read the file in the directory the script is used.
- Make a backup file in the directory the script is used.
- Rename files in the directory the script is used.
- Remove a backup file in the directory the script is used.
- Change the current working directory temporarily (so that local image paths are resolved correctly).
Apart from editing the config file, all operations of the script require Anki to be running.
New in v2.7.0 - if you supply Anki Path and Anki Profile, the script will automatically attempt to open Anki if it isn't already running.
The GUI of the script looks like this:

Hopefully the options and path are self-explanatory. The 'recurse' option can be used on the top-level notes directory - it'll pick up all the notes in subfolders automatically. Note that you can run the script over the same file twice perfectly fine - it won't add duplicate cards.
If you set 'GUI' in the config file to False, the script is then run from the command line:
- Use
-hto see help. - Run the script as
obsidian_to_anki.py [path], where[path]is the path to the file or folder you wish to add notes from. - Use
-cto open up the config file for editing (not guaranteed to work on all operating systems, if it doesn't you'll have to find and edit it manually). - Use
-uto update the config file. Do this when you add new note types to Anki. - Use
-mto force the script to add all media files detected, instead of lazy addition of media files. Useful if you've e.g. resized the image, and want the changes to be reflected in Anki. - Use
-rto use custom regex syntax, ignoring the default syntax of the script. - Use
-Rto recursively scan subfolders.
If you are a new user, these steps are recommended:
- Check Custom syntax to see if there is a template that works for you.
- Then, check the information on the following topics:
- Adding to user-specified decks, on a per-file basis.
- Markdown formatting, including math formatting
- Embedded images. GIFs should work too.
- Auto-deleting notes from the file.
- File tag formatting.
- Easy cloze formatting - A more compact syntax to do Cloze text
- Defaults.
- You should be good to go simply running the script with the 'Regex' option checked.
The sections below describe the default syntax of the script (with the 'Regex' option not checked).
By default, the script adds to the current profile in Anki.