High-performance Anki (.apkg) deck extractor. Liberate your flashcards from Anki's database into clean, actionable JSON and media assets.
Anki Universal Extractor is a robust, script-based solution built with Bun and TypeScript to process .apkg files. It automates the extraction of notes (converted to JSON) and associated media files (audio/images) from any Anki deck, bypassing database locking issues and template complexities.
- ✨ Key Features
- ❓ Why Anki Universal Extractor?
- 🚀 Quick Start
- 🛠️ Usage
- 📂 Project Structure
- 📝 Data Format
- 🤝 Contributing
- ⚡ Blazing Fast: Leverages Bun's native SQLite module for near-instant extraction.
- 🔄 Universal Field Mapping: Automatically detects and maps dynamic field names from any Anki template (No hardcoded field names).
- 📦 Media Integrity: Extracts and organizes images, audio, and videos with their original filenames.
- 🛡️ Windows Friendly: Handles database locking gracefully to prevent extraction errors on Windows systems.
- 📄 Clean JSON Output: Generates a standard JSON structure ready for web apps, print tools, or AI processing.
Extracting data from Anki can be "deceptively simple" until you encounter:
- Database Locks: Accessing
collection.anki2while Anki is open or through standard tools often fails. - Complex Schemas: Different decks use different field names (e.g., "Hanzi" vs "Front"). This tool maps them dynamically based on the deck's metadata.
- Media Mapping: Anki stores media filenames numerically in a JSON map; this tool restores their human-readable names automatically.
- Bun Runtime (Required for SQLite performance and TS execution)
# Clone the repository
git clone https://github.com/srsergi0/anki-universal-extractor.git
# Enter the directory
cd anki-universal-extractor
# Install dependencies
bun installYou can run the extractor directly without installing it using bun x, or run it locally after installation.
Convert any .apkg file to JSON and a media folder instantly:
bun x github:srsergi0/anki-universal-extractor ./path/to/your/deck.apkgIf you have cloned the repo and run bun install:
bun run anki-extract.ts ./path/to/your/deck.apkgdeck.json: A complete database of your cards.deck_media/: A folder containing all associated media files.
anki-extract.ts: The main extraction engine.data/: (Recommended) Place your source.apkgfiles here.package.json: Configuration and dependencies.
The output JSON provides a flat, developer-friendly structure:
[
{
"Front": "Question or Term",
"Back": "Answer or Definition",
"Notes": "Extra information",
"_tags": ["Tag1", "Tag2"],
"_modelId": 123456789
}
]Contributions are welcome! Whether it's fixing bugs, adding features, or improving documentation, feel free to open a Pull Request.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
Distributed under the MIT License. See LICENSE for more information.