minute read

Files

You are reading our Automation1 API documentation for the Python™ programming language.

The Basics

In the Python API, Files lets you read and write controller files on the Automation1 controller. Each Automation1 controller has its own file system in which you can store the controller files.

How to Use

Similar to other file systems, Files lets you do all the options that follow:

  • Read and write controller files. You can read or write controller files as string text or as byte arrays.
  • Get a list of all the controller files.
  • Delete controller files.

When you read or write a controller file, you read or write all of its contents. You cannot open or change part of a controller file.

To access one or more of the controller files, use the Controller.files property. Refer to the example that follows.

Copy
contents = controller.files.read_bytes(controller_file_name)
controller.files.write_bytes(controller_file_name, file_bytes_content)

contents = controller.files.read_text(controller_file_name)
controller.files.write_text(controller_file_name, file_text_content)

controller.files.delete(controller_file_name)

all_files = controller.files.get_files()

Example Code

Copy
import automation1 as a1

controller = a1.Controller.connect()

controller.files.write_text("MyExampleFile.txt", "Hello world!")

file_contents = controller.files.read_text("MyExampleFile.txt")
print(file_contents)

controller.files.delete("MyExampleFile.txt")

Thread Safety

The threading library is the only multithreading library that is officially supported by the Automation1 Python API.

All the methods and properties that operate under the Controller.files property are thread safe. You can call them from two or more threads without interference.

Full Reference

For more information about all the methods that are available for Files, refer to the list that follows.

Controller.files Methods