Paths and Searching#

Convenience functions to find the database and other system locations without the user having to specify full paths.

ankipandas.paths.find_db(search_paths=None, maxdepth=8, filename='collection.anki2', user=None, break_on_first=True) Path[source]#

Find path to anki2 database.

  • search_paths – Search path as string or pathlib object or list/iterable thereof. If None, some search paths are set by default.

  • maxdepth – Maximal search depth.

  • filename – Filename of the collection (default: collections.anki2)

  • user – Username to which the collection belongs. If None, search for databases of any user.

  • break_on_first – Stop searching once a database is found. This is obviously faster, but you will not get any errors if there are multiple databases matching your criteria.


If none or more than one result is foundValueError


Path to the anki2 database

ankipandas.paths.db_path_input(path: str | PurePath | None = None, user: str | None = None) Path[source]#

Helper function to interpret user input of path to database.

  1. If no path is given, we search through some default locations

  2. If path points to a file: Take that file

  3. If path points to a directory: Search in that directory

  • path – Path to database or search path or None

  • user – User name of anki collection or None


Path to anki database as Path object

ankipandas.paths.db_backup_file_name() str[source]#

Time based file name of the backup file.

ankipandas.paths.get_anki_backup_folder(path: str | PurePath, nexist='raise') Path[source]#

Return path to Anki backup folder.

  • path – Path to Aki database as Path

  • nexist – What to do if backup folder doesn’t seem to exist: raise or ignore.


Path to Anki backup folder as Path.

ankipandas.paths.backup_db(db_path: str | PurePath, backup_folder: str | PurePath | None = None) Path[source]#

Back up database file.

  • db_path – Path to database

  • backup_folder – Path to backup folder. If None is given, the backup is created in the Anki backup directory.


Path to newly created backup file as Path.