Skip to content

Converter

Converter module for autopylot. This module contains functions to convert between different data types.

Examples:

>>> from autopylot import converter
>>> converter.csv_to_excel(input_filepath='tests\demo.csv', output_folder='tests')
>>> converter.base64_to_image(input_filepath='tests\demo.txt')
>>> converter.image_to_base64(input_filepath='tests\demo.png', output_folder='tests')
>>> converter.jpg_to_png(input_filepath='tests\demo.jpg', output_folder='tests')
>>> converter.png_to_jpg(input_filepath='tests\demo.png', output_folder='tests')
>>> converter.excel_to_html(input_filepath='tests\demo.xlsx', output_folder='tests')

The module contains the following functions:

  • csv_to_excel(input_filepath, output_folder, output_filename, contains_headers, sep): Convert a CSV file to an Excel file.
  • excel_to_html(input_filepath, output_folder, output_filename): Convert an Excel file to an HTML file.
  • image_to_base64(input_filepath): Convert an image to a base64 string.
  • base64_to_image(input_text, output_folder, output_filename): Convert a base64 string to an image.
  • jpg_to_png(input_filepath, output_folder, output_filename): Convert a JPG image to a PNG image.
  • png_to_jpg(input_filepath, output_folder, output_filename): Convert a PNG image to a JPG image.

base64_to_image(input_text, output_folder, output_filename=None)

Get an image from a base64 encoded string.

Parameters:

Name Type Description Default
input_text str

The base64 encoded string.

required
output_folder str || WindowsPath

The path to the output folder.

required
output_filename str default ending with .png

The name of the output file.

None

Returns:

Type Description
None

None

Examples:

>>> converter.base64_to_image(input_text=base_64_string, output_folder='tests')

csv_to_excel(input_filepath, output_folder, output_filename=None, contains_headers=True, sep=',')

Convert a CSV file to an Excel file.

Parameters:

Name Type Description Default
input_filepath str || WindowsPath

The path to the CSV file.

required
output_folder str || WindowsPath

The path to the output folder.

required
output_filename str

The name of the output file.

None
contains_headers bool

Whether the CSV file contains headers.

True
sep str

The separator used in the CSV file.

','

Returns:

Type Description
None

None

Examples:

>>> converter.csv_to_excel(input_filepath='tests\demo.csv', output_folder='tests')

excel_to_html(input_filepath, output_folder, output_filename=None)

Converts the excel file to colored html file

Parameters:

Name Type Description Default
input_filepath str || WindowsPath

Input excel file path

required
output_folder str || WindowsPath

Output folder path

required
output_filename str

Output file name

None

Returns:

Type Description
None

None

Examples:

>>> converter.excel_to_html(input_filepath='tests\demo.xlsx', output_folder='tests')

image_to_base64(input_filepath)

Get a base64 encoded string from an image.

Parameters:

Name Type Description Default
input_filepath str || WindowsPath

The path to the image file.

required

Returns:

Name Type Description
base_64string str

The base64 encoded string.

Examples:

>>> converter.image_to_base64(input_filepath='tests\demo.png')

image_to_webp(input_filepath, output_folder, output_filename=None)

Converts the image from png to jpg format

Parameters:

Name Type Description Default
input_filepath str || WindowsPath

Input image file path

required
output_folder str || WindowsPath

Output folder path

required
output_filename str

Output file name

None

Returns:

Type Description
None

None

Examples:

>>> converter.image_to_webp(input_filepath='tests\demo.png', output_folder='tests')

jpg_to_png(input_filepath, output_folder, output_filename=None)

Convert a JPG image to a PNG image.

Parameters:

Name Type Description Default
input_filepath str || WindowsPath

The path to the JPG image.

required
output_folder str || WindowsPath

The path to the output folder.

required
output_filename str

The name of the output file.

None

Returns:

Type Description
None

None

Examples:

>>> converter.jpg_to_png(input_filepath='tests\demo.jpg', output_folder='tests')

png_to_jpg(input_filepath, output_folder, output_filename=None)

Converts the image from png to jpg format

Parameters:

Name Type Description Default
input_filepath str || WindowsPath

Input image file path

required
output_folder str || WindowsPath

Output folder path

required
output_filename str

Output file name

None

Returns:

Type Description
None

None

Examples:

>>> converter.png_to_jpg(input_filepath='tests\demo.png', output_folder='tests')