{"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,"search_vec":"'0.13.1':11 '2.1':14 '3.6':19 'anki':6,13,26 'api':23 'apkg':16 'current':9 'deck':7,29 'deck-gener':28 'flashcard':27 'genanki':1 'generat':5,30 'infrequ':22 'librari':3 'programmat':8 'python':18 'releas':20 'repetit':33 'requir':17 'space':32 'spaced-repetit':31 'stabl':25 'support':12 'version':10 'via':15","created_at":"2026-05-09T05:52:07.783540+00:00","updated_at":"2026-05-09T05:52:07.783540+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"http://github.com/kerrickstaley/genanki","docs":null,"changelog":null,"pypi":"https://pypi.org/project/genanki/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-29","last_verified":"2026-06-29","next_check":"2026-07-29","install_tag":null}}