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.
- 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 or more than one result is found –
ValueError
- Returns:
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.
If no path is given, we search through some default locations
If path points to a file: Take that file
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:
If path does not exist –
FileNotFoundError
In various other cases –
ValueError
- ankipandas.paths.get_anki_backup_folder(path: str | PurePath, nexist='raise') 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
orignore
.
- Returns:
Path to Anki backup folder as
Path
.
- ankipandas.paths.backup_db(db_path: str | PurePath, backup_folder: PurePath | str | None = None) 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
.