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) pathlib.Path[source]

Find path to anki2 database.

Parameters
  • 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.

Raises

If none ore more than one result is foundValueError

Returns

Path to the anki2 database

ankipandas.paths.db_path_input(path: Union[str, pathlib.PurePath] = None, user: str = None) pathlib.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

Parameters
  • path – Path to database or search path or None

  • user – User name of anki collection or None

Returns

Path to anki database as Path object

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

Time based file name of the backup file.

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

Return path to Anki backup folder.

Parameters
  • path – Path to Aki database as Path

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

Returns

Path to Anki backup folder as Path.

ankipandas.paths.backup_db(db_path: Union[str, pathlib.PurePath], backup_folder: Optional[Union[pathlib.PurePath, str]] = None) pathlib.Path[source]

Back up database file.

Parameters
  • db_path – Path to database

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

Returns

Path to newly created backup file as Path.