{"id":27795,"library":"genanki","title":"genanki","description":"A library for generating Anki decks programmatically. Current version 0.13.1, supports Anki 2.1+ (via .apkg), requires Python 3.6+. Releases are infrequent; API is stable.","status":"active","version":"0.13.1","language":"python","source_language":"en","source_url":"https://github.com/kerrickstaley/genanki","tags":["anki","flashcards","deck-generation","spaced-repetition"],"install":[{"cmd":"pip install genanki","lang":"bash","label":"Install from PyPI"}],"dependencies":[{"reason":"Compression for .apkg (zip replacement). Included automatically.","package":"cramjam","optional":true}],"imports":[{"note":"","wrong":"","symbol":"Note","correct":"from genanki import Note"},{"note":"","wrong":"","symbol":"Deck","correct":"from genanki import Deck"},{"note":"","wrong":"","symbol":"Package","correct":"from genanki import Package"},{"note":"","wrong":"","symbol":"Model","correct":"from genanki import Model"}],"quickstart":{"code":"import genanki\n\n# Define a model (card template)\nmy_model = genanki.Model(\n  1607392319,\n  'Simple Model',\n  fields=[\n    {'name': 'Question'},\n    {'name': 'Answer'},\n  ],\n  templates=[\n    {\n      'name': 'Card 1',\n      'qfmt': '{{Question}}',\n      'afmt': '{{FrontSide}}<hr id=\"answer\">{{Answer}}',\n    },\n  ])\n\n# Create a deck with a unique ID\ndeck = genanki.Deck(\n  2059400110,\n  'My Deck')\n\n# Add notes (cards) to the deck\nnote = genanki.Note(\n  model=my_model,\n  fields=['Capital of France?', 'Paris'])\ndeck.add_note(note)\n\n# Generate .apkg file\npackage = genanki.Package(deck)\npackage.write_to_file('output.apkg')\n\nprint('Deck generated successfully!')","lang":"python","description":"Creates a simple Anki deck with one card and writes it to output.apkg."},"warnings":[{"fix":"Use a random 10-digit integer or a timestamp-based ID: genanki.Deck(int(time.time()*1000), 'Deck Name')","message":"Model IDs and Deck IDs must be unique and not collide with existing IDs in Anki. Use random large integers (e.g., from time-based generators) to avoid conflicts.","severity":"gotcha","affected_versions":"all"},{"fix":"Regenerate the entire deck programmatically instead of trying to edit the .apkg directly.","message":"The .apkg file is a ZIP archive. If you need to modify it, you must rebuild the deck from scratch; genanki does not support appending to existing decks.","severity":"gotcha","affected_versions":"all"},{"fix":"package = genanki.Package(deck); package.media_files = ['image.jpg']","message":"Media files (images, audio) must be added via Package.media_files before writing. Simply linking in the note fields is not enough.","severity":"gotcha","affected_versions":"all"}],"env_vars":null,"last_verified":"2026-05-09T00:00:00.000Z","next_check":"2026-08-07T00:00:00.000Z","problems":[{"fix":"Run: pip install genanki","cause":"Package not installed; or virtual environment not activated.","error":"ModuleNotFoundError: No module named 'genanki'"},{"fix":"Use a unique ID for each model, e.g., import random; model_id = random.randrange(1<<30, 1<<31)","cause":"Reusing a Model ID that conflicts with an existing one in the same deck (or across decks).","error":"ValueError: Model ID 1607392319 is already used by another model in this deck."},{"fix":"package.write_to_file('deck.apkg')","cause":"Forget to pass filename to write_to_file; it's a method, not a property.","error":"TypeError: write_to_file() missing 1 required positional argument: 'filename'"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}