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​

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

Convert data to the format required for creating entities

Parameters:

NameTypeDescriptionDefault
input

Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame

required
entity_classstr

The entity class to write to the CSV file as the first column

required
unique_keyOptional[str]

(optional) An existing key to call out as a constraint

None

Returns:

TypeDescription

A pandas DataFrame with the entity class as the first column

write_entity_csv​

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

Write data to a CSV file for creating entities

Parameters:

NameTypeDescriptionDefault
filenamestr

The name of the file to write to. Recommended to end in ".entity.csv".

required
input

Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame

required
**kwargs

Options forwarded to the corresponding conversion function.

{}

Other Parameters:

NameTypeDescription
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​

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

Parameters:

NameTypeDescriptionDefault
input

Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame

required
source_columnstr

The name of the column that contains the image data

required
source_typeOptional[str]

(optional) The type the source column. If not specified, the source column will be used. Should be one of "filename", "url", "gsurl", or "s3url".

None
formatOptional[str]

(optional) The format of the image data. If not provided, there should be a column called "format" in the input data.

None
unique_keyOptional[str]

(optional) An existing key to call out as a constraint

None

Returns:

TypeDescription

A pandas DataFrame with the source column as the first column

write_image_csv​

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

Write data to a CSV file for creating images

Parameters:

NameTypeDescriptionDefault
filenamestr

The name of the file to write to. Recommended to end in ".image.csv".

required
input

Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame

required
**kwargs

Options forwarded to the corresponding conversion function.

{}

Other Parameters:

NameTypeDescription
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​

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

Parameters:

NameTypeDescriptionDefault
input

Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame

required
connection_classstr

The connection class to write to the CSV file as the first column

required
source_classstr

The source entity class

required
source_propertystr

The property containing the source key in ApertureDB

required
destination_classstr

The destination entity class

required
destination_propertystr

The property of the destination entity in ApertureDB

required
source_columnOptional[str]

(optional) The column containing the source keys in the input data. Defaults to the source_property.

None
destination_columnOptional[str]

(optional) The column containing the destination keys in the input data. Defaults to the destination_property.

None
unique_keyOptional[str]

(optional) An existing key to call out as a constraint

None

write_connection_csv​

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

Write data to a CSV file for creating connections

Parameters:

NameTypeDescriptionDefault
filenamestr

The name of the file to write to. Recommended to end in ".connection.csv".

required
input

Anything that can be used as input to a pandas DataFrame, including a pandas DataFrame

required
**kwargs

Options forwarded to the corresponding conversion function.

{}

Other Parameters:

NameTypeDescription
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