Available starting from v 6.2

Reading from and writing to TIS Files in the Python operator is possible via the files parameter in either the simple_main or create_table functions. In the basic main function TIS files can be accessed via the keyword arguments parameter **kwargs.

TIS File I/O in the run, simple_main and create_table functions

These functions provide the files argument that serves as the entry point for TIS file read and write access. Since simple_main and create_table can be defined as asynchronous functions, the file I/O API is provided in an asynchronous or a blocking fashion, depending on whether an asynchronous entry method has been used or not. Both APIs are very similar from a naming perspective, though the asynchronous version is to be used in conjunction with Python's async language keywords (asyncawait and  yield). The object stored in the files argument is of type FilesProvider.

class FilesProvider

FilesProvider has 2 properties i and o that each return a list of file stream providers for the input files and output files respectively. The order of the stream providers is determined by the order of the file paths specified in the Input files and Output files operator settings.

class InFileStreamProvider

bytereader()

async api: Returns an asyncio.StreamReader.

sync api: Returns an io.BytesIO object.

textreader(encoding='UTF-8', errors='strict', newline='\r\n')

errors defines decoding/encoding error handling.

When using the readline() function of the text reader newline is expected to be the end-of-line character sequence. The default is: Windows-style.

More details about the arguments can be found here.

async api: Returns an AsyncTextIOWrapper.

sync api: Returns an io.TextIOWrapper.

class OutFileStreamProvider

bytewriter()

async api: Returns a BufferedStreamWriter.

sync api: Returns an io.BytesIO object.

textwriter(encoding='UTF-8', errors='strict')

The arguments are the same as for InFileStreamProvider.textreader().

async api: Returns an AsyncTextIOWrapper.

sync api: Returns an io.TextIOWrapper.

class AsyncTextIOWrapper

A wrapper of asyncio.StreamReader and BufferedStreamWriter that exposes text stream reader and writer functions with decoding/encoding support. The object is asynchronously iterable on a line-by-line basis.

async read(n=-1)

Reads n characters from the stream and returns them as decoded text. If n is -1, the entire stream is read. If this is an out file stream, this function raises an error. If the stream is at EOF, an empty string is returned.

async readline()

Reads a line and returns it as decoded text. If this is an out file stream, this function raises an error. If the stream is at EOF, an empty string is returned.

write(s)

Encodes s and writes it to the buffer. If this is an in file stream, this function raises an error.

async write_async(s)

Encodes s, writes it to the buffer and flushes the buffer automatically. If this is an in file stream, this function raises an error.

writelines(lines)

Encodes a list of text lines and writes it to the buffer. Newline characters are not added automatically to the lines. If this is an in file stream, this function raises an error.

async writelines_async(lines)

Encodes a list of text lines, writes it to the buffer and flushes the buffer automatically. Newline characters are not added automatically to the lines. If this is an in file stream, this function raises an error.

async drain()

Flushes the buffer.

class BufferedStreamWriter

A buffered byte stream writer. Inherits asyncio.StreamWriter.

write(data)

Writes data to the buffer.

async write_async(data)

Writes data to the buffer and flushes the buffer automatically.

writelines(data)

Writes data as list of lines to the buffer. Newline characters are not added automatically to the lines.

async writelines_async(data)

Writes data as list of lines to the buffer and flushes the buffer automatically. Newline characters are not added automatically to the lines.

async drain()

Flushes the buffer.


TIS File I/O in the main function

The main function has an optional 4th argument **kwargs, which is a dictionary of additional arguments. Among those are the filereaders and filewriters arguments. These contain asyncio.StreamReader and BufferedStreamWriter objects, in the order of the file paths specified in the Input files and Output files operator settings.

Related topics