Generate Anki flashcards with Python
Create and activate a virtual environment, then install the public PyPI package:
python -m venv .venv. .venv/bin/activatepython -m pip install ankiforge==0.3.1On Windows, activate with .venv\Scripts\Activate.ps1.
Use ordinary CPython 3.11 or later and a matching platform wheel; CPython 3.11–3.14 is covered by recorded release checks; see verified environments.
Export a deck
Section titled “Export a deck”Save this as main.py:
from ankiforge import Project, Note, BuildOptions
project = Project('spanish', default_deck='Spanish')project.add('es:hola', Note.basic('hola', 'hello'))output = project.build(BuildOptions.to('spanish.apkg'))print(output.artifact.path)python main.pyOpen the persistent spanish.apkg in Anki. It contains hola → hello in Spanish.
Keep namespace spanish and note key es:hola stable for later edits. Exporting does not require Anki to be installed.
Continue
Section titled “Continue”For a vocabulary spreadsheet, follow CSV to Anki. To draft cards from source notes, start with AI-assisted card generation.
For a complete media and update task, follow JSON to Anki.
- Images and audio and Python media API
- Custom note types and template bundles
- Image Occlusion
- Compare and update
- Python API and diagnostics
- Move from genanki
For native source builds, use source builds.