Raw Dataframes

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: Union[str, pathlib.PurePath]) → sqlite3.Connection[source]

Load database from path.

Parameters:path – String or pathlib.PurePath.
Returns:sqlite3.Connection
ankipandas.raw.close_db(db: sqlite3.Connection) → None[source]

Close the database.

Parameters:db – Database (sqlite3.Connection)
Returns:None
ankipandas.raw.get_table(db: sqlite3.Connection, table: str) → pandas.core.frame.DataFrame[source]

Get raw table from the Anki database.

Parameters:
Returns:

pandas.DataFrame

ankipandas.raw.get_empty_table(table: str) → pandas.core.frame.DataFrame[source]

Get empty table

Parameters:tablecards, notes or revs
Returns:class: pandas.DataFrame
ankipandas.raw.get_info[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.set_table(db: sqlite3.Connection, df: pandas.core.frame.DataFrame, table: str, mode: str, id_column='id') → None[source]

Write table back to database.

Parameters:
  • db – Database (sqlite3.Connection)
  • df – The pandas.DataFrame to write
  • table – 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: json.encoder.JSONEncoder

JSON Encoder that support numpy datatypes by converting them to built in datatypes.

default(obj)[source]
ankipandas.raw.set_info(db: sqlite3.Connection, info: dict) → None[source]

Write back extra info to database

Parameters:
Returns:

None

ankipandas.raw.get_ids[source]

Get list of IDs, e.g. note IDs etc.

Parameters:
Returns:

Nested dictionary

ankipandas.raw.get_deck_info[source]

Get information about decks.

Parameters:db – Database (sqlite3.Connection)
Returns:Nested dictionary
ankipandas.raw.get_did2deck[source]

Mapping of deck IDs (did) to deck names.

Parameters:db – Database (sqlite3.Connection)
Returns:Dictionary mapping
ankipandas.raw.get_deck2did[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[source]

Get information about models.

Parameters:db – Database (sqlite3.Connection)
Returns:Nested dictionary
ankipandas.raw.get_mid2model[source]

Mapping of model IDs (mid) to model names.

Parameters:db – Database (sqlite3.Connection)
Returns:Dictionary mapping
ankipandas.raw.get_model2mid[source]

Mapping of model name to model ID (mid)

Parameters:db – Database (sqlite3.Connection)
Returns:Dictionary mapping
ankipandas.raw.get_mid2sortfield[source]

Mapping of model ID to index of sort field.

ankipandas.raw.get_mid2fields[source]

Get mapping of model ID to field names.

Parameters:db – Databse (sqlite3.Connection)
Returns:Dictionary mapping of model ID (mid) to list of field names.
ankipandas.raw.get_cid2nid[source]

Mapping card ID to note ID.

Parameters:db – Database (sqlite3.Connection)
Returns:Dictionary
ankipandas.raw.get_cid2did[source]

Mapping card ID to deck ID.

Parameters:db – Database (sqlite3.Connection)
Returns:Dictionary
ankipandas.raw.get_nid2mid[source]

Mapping note ID to model ID.

Parameters:db – Database (sqlite3.Connection)
Returns:Dictionary