Collection#
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.- Parameters:
path – (Search) path to database. See
db_path_input()
for more information.user – Anki user name. See
db_path_input()
for more information.
Examples:
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 db: Connection#
Opened Anki database. Make sure to call db.close() after you’re done. Better still, use contextlib.closing.
- property notes: AnkiDataFrame#
Notes as
ankipandas.ankidf.AnkiDataFrame
.
- property cards: AnkiDataFrame#
Cards as
ankipandas.ankidf.AnkiDataFrame
.
- property revs: AnkiDataFrame#
Reviews as
ankipandas.ankidf.AnkiDataFrame
.
- empty_notes()[source]#
Similar
ankipandas.ankidf.AnkiDataFrame
tonotes
, but without any rows.
- empty_cards()[source]#
Similar
ankipandas.ankidf.AnkiDataFrame
tocards
, but without any rows.
- empty_revs()[source]#
Similar
ankipandas.ankidf.AnkiDataFrame
torevs
, 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.
- Parameters:
output – Output mode: ‘print’ (default: print) or ‘dict’ (return as dictionary of dictionaries of format
{<type (cards/notes/...)>: {<key>: <value>}}
.- Returns:
None or dictionary of dictionaries
- write(modify=False, add=False, delete=False, backup_folder: PurePath | str | None = None, _override_exception=False)[source]#
Creates a backup of the database and then writes back the new data.
Danger
The write capabilities of
AnkiPandas
have currently been disabled because of #137. Help in fixing this issue would be greatly appreciated!Danger
The switches
modify
,add
anddelete
will run additional cross-checks, but do not rely on them to 100%!Warning
It is recommended to run
summarize_changes()
before to check whether the changes match your expectation.Note
Please make sure to thoroughly check your collection in Anki after every write process!
- Parameters:
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).
- Returns:
None