This is the starting point for most end-users. The Collection class loads the Anki collection and provides access to its notes, cards and reviews as pandas DataFrame objects.

class ankipandas.collection.Collection(path=None, user=None)[source]#

Bases: object

__init__(path=None, user=None)[source]#

Initialize Collection object.

  • path โ€“ (Search) path to database. See db_path_input() for more information.

  • user โ€“ Anki user name. See db_path_input() for more information.


from ankipandas import Collection

# Let ankipandas find the db for you
col = Collection()

# Let ankipandas find the db for this user (important if you have
# more than one user account in Anki)
col = Collection(user="User 1")

# Specify full path to Anki's database
col = Collection("/full/path/to/collection.anki2")

# Specify partial path to Anki's database and specify user
col = Collection("/partial/path/to/collection", user="User 1")
property path: pathlib.Path#

Path to currently loaded database

property db: sqlite3.Connection#

Opened Anki database. Make sure to call db.close() after youโ€™re done. Better still, use contextlib.closing.

property notes: ankipandas.ankidf.AnkiDataFrame#

Notes as ankipandas.ankidf.AnkiDataFrame.

property cards: ankipandas.ankidf.AnkiDataFrame#

Cards as ankipandas.ankidf.AnkiDataFrame.

property revs: ankipandas.ankidf.AnkiDataFrame#

Reviews as ankipandas.ankidf.AnkiDataFrame.


Similar ankipandas.ankidf.AnkiDataFrame to notes, but without any rows.


Similar ankipandas.ankidf.AnkiDataFrame to cards, but without any rows.


Similar ankipandas.ankidf.AnkiDataFrame to revs, but without any rows.

summarize_changes(output='print') dict[str, dict] | None[source]#

Summarize changes that were made with respect to the table as loaded from the database. If notes/cards/etc. were not loaded at all (and hence also definitely not modified), they do not appear in the output.


output โ€“ Output mode: โ€˜printโ€™ (default: print) or โ€˜dictโ€™ (return as dictionary of dictionaries of format {<type (cards/notes/...)>: {<key>: <value>}}.


None or dictionary of dictionaries

write(modify=False, add=False, delete=False, backup_folder: PurePath | str | None = None)[source]#

Creates a backup of the database and then writes back the new data.


The switches modify, add and delete will run additional cross-checks, but do not rely on them to 100%!


It is recommended to run summarize_changes() before to check whether the changes match your expectation.


Please make sure to thoroughly check your collection in Anki after every write process!

  • modify โ€“ Allow modification of existing items (notes, cards, etc.)

  • add โ€“ Allow adding of new items (notes, cards, etc.)

  • delete โ€“ Allow deletion of items (notes, cards, etc.)

  • backup_folder โ€“ Path to backup folder. If None is given, the backup is created in the Anki backup directory (if found).