Internals#
These function implement the more direct interactions with the Anki
database and provide basic functionality that is then used to implement the
functionality in Collection,
ankipandas.ankidf.AnkiDataFrame etc.
Warning
Please only use these function if you know what you are doing, as they
come with less consistency checks as the functionality implemented in
Collection and
ankipandas.ankidf.AnkiDataFrame.
Also note that the functions here are considered to be internal, i.e. might
change without prior notice.
- ankipandas.raw.load_db(path: str | pathlib.PurePath) sqlite3.Connection[source]#
Load database from path.
- Parameters:
path – String or
pathlib.PurePath.- Returns:
- ankipandas.raw.close_db(db: Connection) None[source]#
Close the database.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
None
- ankipandas.raw.get_table(db: Connection, table: str) DataFrame[source]#
Get raw table from the Anki database.
- Parameters:
db – Database (
sqlite3.Connection)table –
cards,notesorrevs
- Returns:
pandas.DataFrame
- ankipandas.raw.get_empty_table(table: str) DataFrame[source]#
Get empty table
- Parameters:
table –
cards,notesorrevs- Returns:
class: pandas.DataFrame
- ankipandas.raw.read_info(db: Connection, table_name: str) dict[source]#
Get a table from the database and return nested dictionary mapping of it.
- Parameters:
db –
table_name –
Returns:
- ankipandas.raw.get_info(db: Connection) dict[source]#
Get all other information from the database, e.g. information about models, decks etc.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Nested dictionary.
- ankipandas.raw.get_db_version(db: Connection) int[source]#
Get “version” of database structure
- Parameters:
db –
- Returns: 0: all info (also for decks and models) was in the ‘col’ table
1: separate ‘notetypes’ and ‘decks’ tables
- ankipandas.raw.set_table(db: Connection, df: DataFrame, table: str, mode: str, id_column='id') None[source]#
Write table back to database.
- Parameters:
db – Database (
sqlite3.Connection)df – The
pandas.DataFrameto writetable – Table to write to: ‘notes’, ‘cards’, ‘revs’
mode – ‘update’: Update all existing entries, ‘append’: Only append new entries, but do not modify, ‘replace’: Append, modify and delete
id_column – Column with ID
- Returns:
None
- class ankipandas.raw.NumpyJSONEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]#
Bases:
JSONEncoderJSON Encoder that support numpy datatypes by converting them to built in datatypes.
- ankipandas.raw.set_info(db: Connection, info: dict) None[source]#
Write back extra info to database
- Parameters:
db – Database (
sqlite3.Connection)info – Output of
get_info()
- Returns:
None
- ankipandas.raw.update_note_indices(db: Connection) None[source]#
Update search indices for ‘notes’ table. This does not modify any information in the table itself. See klieret/AnkiPandas#124 for more informationl
- ankipandas.raw.update_card_indices(db: Connection) None[source]#
Update search indices for ‘cards’ table. This does not modify any information in the table itself. See klieret/AnkiPandas#124 for more informationl
- ankipandas.raw.get_ids(db: sqlite3.Connection, table: str) list[int][source]#
Get list of IDs, e.g. note IDs etc.
- Parameters:
db – Database (
sqlite3.Connection)table – ‘revs’, ‘cards’, ‘notes’
- Returns:
Nested dictionary
- ankipandas.raw.get_deck_info(db: Connection) dict[source]#
Get information about decks.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Nested dictionary
- ankipandas.raw.get_did2deck(db: sqlite3.Connection) dict[int, str][source]#
Mapping of deck IDs (did) to deck names.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Dictionary mapping
- ankipandas.raw.get_deck2did(db: sqlite3.Connection) dict[str, int][source]#
Mapping of deck names to deck IDs
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Dictionary mapping of deck id to deck name
- ankipandas.raw.get_model_info(db: Connection) dict[source]#
Get information about models.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Nested dictionary
- ankipandas.raw.get_mid2model(db: sqlite3.Connection) dict[int, str][source]#
Mapping of model IDs (mid) to model names.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Dictionary mapping
- ankipandas.raw.get_model2mid(db: sqlite3.Connection) dict[str, int][source]#
Mapping of model name to model ID (mid)
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Dictionary mapping
- ankipandas.raw.get_mid2sortfield(db: sqlite3.Connection) dict[int, int][source]#
Mapping of model ID to index of sort field.
- ankipandas.raw.get_mid2fields(db: sqlite3.Connection) dict[int, list[str]][source]#
Get mapping of model ID to field names.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Dictionary mapping of model ID (mid) to list of field names.
- ankipandas.raw.get_mid2templateords(db: sqlite3.Connection) dict[int, list[int]][source]#
Get mapping of model ID to available templates ids
- Parameters:
db –
Returns:
- ankipandas.raw.get_cid2nid(db: sqlite3.Connection) dict[int, int][source]#
Mapping card ID to note ID.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Dictionary
- ankipandas.raw.get_cid2did(db: sqlite3.Connection) dict[int, int][source]#
Mapping card ID to deck ID.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Dictionary
- ankipandas.raw.get_nid2mid(db: sqlite3.Connection) dict[int, int][source]#
Mapping note ID to model ID.
- Parameters:
db – Database (
sqlite3.Connection)- Returns:
Dictionary