API

imo_vmdb.cleanup(db_conn, logger)

Remove all previously imported data, if any, while preserving normalized data in the database.

This function takes an existing database connection and a logger object as parameters. It removes all previously imported data from the database, leaving normalized data intact.

Parameters:
  • db_conn – An open database connection implementing DB-API 2.0.

  • logger (logging.Logger) – A logger object used to log errors, warnings, and additional information.

Returns:

An integer indicating the result of the operation. 0 for success, other values for errors.

Return type:

int

imo_vmdb.initdb(db_conn, logger)

Initialize an empty database, removing all data if the database already exists.

This function takes an existing database connection and a logger object as parameters. It initializes an empty database, removing all data if the database already exists.

Parameters:
  • db_conn – An open database connection implementing DB-API 2.0.

  • logger (logging.Logger) – A logger object used to log errors, warnings, and additional information.

Returns:

An integer indicating the result of the operation. 0 for success, 1 for errors.

Return type:

int

imo_vmdb.normalize(db_conn, logger)

Establish relationships between imported records and enrich observations with additional information.

This function takes an existing database connection and a logger object as parameters. It establishes relationships between the imported records in the database, enriching observations with additional information.

Parameters:
  • db_conn – An open database connection implementing DB-API 2.0.

  • logger (logging.Logger) – A logger object used to log errors, warnings, and additional information.

Returns:

An integer indicating the result of the operation. 0 for success, 1 for errors.

Return type:

int

class imo_vmdb.CSVImporter(db_conn, logger, do_delete=False, try_repair=False, is_permissive=False)

A class for importing CSV files of various types into a database.

The CSVImporter class allows to import CSV files into a database. You can specify whether to delete existing data, attempt data repair, or be permissive about non-critical data errors during the import.

Parameters:
  • db_conn – An existing database connection implementing DB-API 2.0.

  • logger (logging.Logger) – A logger object used to log errors, warnings, and additional information.

  • do_delete (bool) – If True, delete existing data before importing. Default is False.

  • try_repair (bool) – If True, attempt data repair during import. Default is False.

  • is_permissive (bool) – If True, be permissive about non-critical data errors. Default is False.

run(file_list)

Import CSV files specified in the files_list into the database.

This method imports CSV files into the database, with options to delete existing data, attempt data repair, and be permissive about non-critical data errors. After running this method, you can check the has_errors, counter_read, and counter_write properties of this object to determine the import result.

Parameters:

file_list (list of str) – A list of file paths to CSV files for import.