Using python script to run AT commands

I am new to the FX-30, and I am tasked with writing a python script to enter AT mode, query information with the script, run additional AT commands with the script using the outputs of other AT commands, and log the information to a text file. My script right now attempts to utilize the os import library, however when I do:
os.system(‘microcom -X /dev/ttyAT’)
os.sleep(10)
any os.system command called subsequently will not interact with the terminal in any way since it enters AT mode.
I am unaware of if there is a useful python library within the FX-30 firmware’s libraries to solve this issue, or if there is an alternative method to be used. If anyone has experience on this or possible solutions, input would be greatly appreciated.

does this help?

you might need to rebuild yocto image to include the pyserial library:

For example, in ./meta-swi/meta-swi-mdm9x28/recipes-core/images/mdm9x28-image.inc

IMAGE_INSTALL_append = " python python-pyserial python-argparse python-importlib python-zlib"