Skip to content

Utility

Utility module for autopylot. This module contains utility functions.

Examples:

>>> import autopylot as utility
>>> utility.pause_program(seconds=5)
>>> utility.api_request(url="https://catfact.ninja/fact?max_length=140")
>>> utility.clear_output()
>>> utility.install_module(module_name="requests")
>>> utility.uninstall_module(module_name="requests")
>>> utility.get_module_version(module_name="requests")
>>> utility.image_to_text(image_path="image.png")

This module contains the following functions:

  • pause_program(seconds): Pauses the program for the specified number of seconds
  • api_request(url , method, body, headers): Makes an API request to the specified URL
  • clear_output(): Clears the output of the console
  • install_module(module_name): Installs the specified module
  • uninstall_module(module_name): Uninstalls the specified module
  • get_module_version(module_name): Gets the version of the specified module
  • image_to_text(image_path): Converts the specified image to text

api_request(url, method='GET', body=None, headers=None)

Makes an API request to the specified URL

Parameters:

Name Type Description Default
url str

URL to make request to

required
method str

HTTP method to use for the request. Available options are "GET", "POST", "PUT", "DELETE".

'GET'
body dict

Body of the request.

None
headers dict

Headers of the request.

None

Returns:

Name Type Description
response dict

Response from the API

Examples:

>>> utility.api_request(url="https://catfact.ninja/fact?max_length=140")

clear_output()

Clears the output of the console

Returns:

Type Description
None

None

Examples:

>>> utility.clear_output()

get_module_version(module_name)

Gets the version of the specified module

Parameters:

Name Type Description Default
module_name str

Name of the module to get the version of

required

Returns:

Name Type Description
version str

Version of the specified module

Examples:

>>> utility.get_module_version(module_name="requests")

image_to_text(image_path)

Converts the specified image to text

Parameters:

Name Type Description Default
image_path str || WindowsPath

Path to the image

required

Returns:

Name Type Description
text str

Text from the image

Examples:

>>> utility.image_to_text(image_path="tests\demo2.png")

install_module(module_name)

Installs the specified module

Parameters:

Name Type Description Default
module_name str

Name of the module to install

required

Returns:

Type Description
None

None

Examples:

>>> utility.install_module(module_name="requests")

pause_program(seconds=5)

Pauses the program for the specified number of seconds

Parameters:

Name Type Description Default
seconds float

Number of seconds to pause the program.

5

Returns:

Type Description
None

None

Examples:

>>> utility.pause_program(seconds=5)

uninstall_module(module_name)

Uninstalls the specified module

Parameters:

Name Type Description Default
module_name str

Name of the module to uninstall

required

Returns:

Type Description
None

None

Examples:

>>> utility.uninstall_module(module_name="requests")