Skip to main content

CSVWriter

This file contains some utilities to help with converting existing CSV files to the format required by ApertureDB. The main functions are for writing CSV files for creating entities, images, and connections. The functions take in a pandas DataFrame and write it to a CSV file with the appropriate headers required by the various *CSV loaders in ApertureDB. This makes it easier to generate CSV files without having to remember the exact column names required by the CSV loaders.

convert_entity_data

def convert_entity_data(input,
entity_class: str,
unique_key: Optional[str] = None)

Convert data to the format required for creating entities

Arguments:

  • input - Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame
  • entity_class - The entity class to write to the CSV file as the first column
  • unique_key - (optional) An existing key to call out as a constraint

Returns:

A pandas DataFrame with the entity class as the first column

write_entity_csv

def write_entity_csv(filename: str, input, **kwargs)

Write data to a CSV file for creating entities

Arguments:

  • filename - The name of the file to write to. Recommended to end in ".entity.csv".
  • input - Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame
  • entity_class - The entity class to write to the CSV file as the first column
  • unique_key - (optional) An existing key to call out as a constraint

convert_image_data

def convert_image_data(input,
source_column: str,
source_type: Optional[str] = None,
format: Optional[str] = None,
unique_key: Optional[str] = None)

Convert data to the format required for creating images

Arguments:

  • input - Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame
  • source_column - The name of the column that contains the image data
  • source_type - (optional) The type the source column. If not specified, the source column will be used. Should be one of "filename", "url", "gsurl", or "s3url".
  • format - (optional) The format of the image data. If not provided, there should be a column called "format" in the input data.
  • unique_key - (optional) An existing key to call out as a constraint

Returns:

A pandas DataFrame with the source column as the first column

write_image_csv

def write_image_csv(filename: str, input, **kwargs)

Write data to a CSV file for creating images

Arguments:

  • filename - The name of the file to write to. Recommended to end in ".image.csv".
  • input - Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame
  • source_column - The name of the column that contains the image data
  • source_type - (optional) The type the source column. If not specified, the source column will be used. Should be one of "filename", "url", "gsurl", or "s3url".
  • format - (optional) The format of the image data. If not provided, there should be a column called "format" in the input data.
  • unique_key - (optional) An existing key to call out as a constraint

convert_connection_data

def convert_connection_data(input,
connection_class: str,
source_class: str,
source_property: str,
destination_class: str,
destination_property: str,
source_column: Optional[str] = None,
destination_column: Optional[str] = None,
unique_key: Optional[str] = None)

Convert data to the format required for creating connections

Arguments:

  • input - Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame
  • connection_class - The connection class to write to the CSV file as the first column
  • source_class - The source entity class
  • source_property - The property containing the source key in ApertureDB
  • destination_class - The destination entity class
  • destination_property - The property of the destination entity in ApertureDB
  • source_column - (optional) The column containing the source keys in the input data. Defaults to the source_property.
  • destination_column - (optional) The column containing the destination keys in the input data. Defaults to the destination_property.
  • unique_key - (optional) An existing key to call out as a constraint

write_connection_csv

def write_connection_csv(filename: str, input, **kwargs)

Write data to a CSV file for creating connections

Arguments:

  • filename - The name of the file to write to. Recommended to end in ".connection.csv".
  • input - Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame
  • connection_class - The connection class to write to the CSV file as the first column
  • source_class - The source entity class
  • source_property - The property containing the source key in ApertureDB
  • source_column - (optional) The column containing the source keys in the input data. Defaults to the source_property.
  • destination_class - The destination entity class
  • destination_property - The property of the destination entity in ApertureDB
  • destination_column - (optional) The column containing the destination keys in the input data. Defaults to the destination_property.
  • unique_key - (optional) An existing key to call out as a constraint