Files
anki/pylib
Abdo b758186f25 fix: Add compatibility shims for AnkiPackageImporter/AnkiPackageExporter (#5547)
## Linked issue

Closes #5541

## Summary

Add compatibility wrappers for AnkiPackageImporter/AnkiPackageExporter
to redirect the calls to the new APIs. This is intended as a temporary
compatibility workaround for the
[AnkiConnect](https://ankiweb.net/shared/info/2055492159) add-on, not as
a general wrapper for all removed APIs.

## Steps to reproduce (before)

Install AnkiConnect and confirm it fails at startup due to the removed
`anki.importing` and `anki.exporting` modules.

## How to test (after)

Export a sample apkg and run this script in the same directory to test
AnkiConnect's importPackage/exportPackage APIs.

```python
import json
import urllib.request
from pathlib import Path


def request(action, **params):
    return {'action': action, 'params': params, 'version': 6}

def invoke(action, **params):
    payload = json.dumps(request(action, **params)).encode('utf-8')
    response = json.load(urllib.request.urlopen(urllib.request.Request('http://127.0.0.1:8765', payload)))
    if len(response) != 2:
        raise Exception('response has an unexpected number of fields')
    if 'error' not in response:
        raise Exception('response is missing required error field')
    if 'result' not in response:
        raise Exception('response is missing required result field')
    if response['error'] is not None:
        raise Exception(response['error'])
    return response['result']

result = invoke('importPackage', path=str(Path(__file__).parent / 'sample.apkg'))
assert result is True

decks = invoke('deckNamesAndIds')
deck_to_export = next(name for name in decks if name != 'Default')

result = invoke('exportPackage', deck=deck_to_export, path=str(Path(__file__).parent / 'exported.apkg'), includeSched=True)
assert result is True

```
2026-09-08 21:30:34 +03:00
..
2025-06-27 16:10:12 +07:00

Anki

Build Status

Core Python library for Anki, the spaced repetition flashcard program.

About

Anki is a spaced repetition program that helps you remember things efficiently. This package contains the Python layer of Anki's core: it wraps the Rust backend (rslib) and exposes the primary API used by the desktop app and add-ons alike.

It provides access to:

  • Collection — open, read, and write an Anki .anki2 database
  • Notes & Cards — create, update, and query notes and cards
  • Decks & Models — manage deck configurations and note types
  • Scheduler — the FSRS/SM-2 scheduling algorithms
  • Media — media file management and sync
  • Import / Export — support for .apkg, .colpkg, and other formats
  • Sync — synchronisation with AnkiWeb
  • Hooks — event system for extending behaviour

Installation

pip install anki

Note: anki is the headless library. If you want the full desktop application, install aqt instead, which depends on this package.

Add-on development

If you are building an Anki add-on, this is the package that gives you access to the collection and scheduling internals. See the Add-on Guide for full documentation.

Contributing

Want to contribute? Check out the Contribution Guidelines and the Development Guide.

License

AGPL-3.0-or-later