open_glyuefile
Overview
open_glyuefile()
returns a GlyueFileHandle
object that serves as an interface to an encrypted file (GlyueFile
) in the database. It is meant to almost identically mimic the built-in Python function open()
:
open_glyuefile()
also supports usage in a context manager:
Programmer Interface
open_glyuefile(filename: str, mode='r', encoding=None)
Open a GlyueFile
from the database matching the given filename and tied to the current IntegrationRunHistory
and return a corresponding GlyueFileHandle
object.
filename is a string representing the name of the file without any path. Since an actual file on disk is not being opened, no path is needed. Do not put slashes in your filename. Only one file with any given name can exist in the same integration run, but the same name can be reused across runs.
mode is an optional string that specifies the mode in which the file should be opened. The same modes available in Python’s builtin open()
function are available here. Common modes include ‘r'
for reading, ‘w'
for writing (truncating the file if it already exists), ‘x'
for explicit creation, and 'a'
for appending (all writes are done to the end of the file regardless of seek position). In text mode, if encoding is not passed, the encoding defaults to UTF-8.
Available modes are:
| open for reading (default), fails if file does not exist |
| open for writing, truncating the file first, opens new file if it does not exist |
| open for exclusive creation, failing if the file already exists |
| open for writing, appending to the end of file if it exists |
| binary mode |
| text mode (default) |
| open for updating (reading and writing) |
The default mode is 'r'
(open for reading text, a synonym of 'rt'
). Modes 'w+'
and 'w+b'
open and truncate the file. Modes 'r+'
and 'r+b'
open the file with no truncation.
GlyueFileHandle methods and properties
attribute | type / returns | description |
|
| clears the buffer and closes the file |
|
| value representing whether the file is closed or not |
|
| value of the encoding the file was opened with |
|
| returns the database id of the underlying |
|
| writes changes (if any) to the database |
|
| the mode the file was opened in |
|
| the filename |
|
| returns the next |
|
| returns |
|
| returns the next |
|
| returns a list of the next |
|
| sets the buffer to the current |
|
| returns |
|
| returns the current position of the buffer |
|
| truncates the file to This action is immediately reflected in the database! |
|
| returns |
|
| writes |
|
| writes |
GlyueFileHandle Buffering
All read and write operations are done on the underlying buffer which is either a BytesIO
in binary mode or StringIO
in text mode.
Reading
The file contents from the database are not immediately loaded into the buffer on open, but rather when the data is first needed (such as calling read()
among multiple other methods). At this point the entire contents of the file have been loaded into the buffer (and thus, memory), regardless of whether or not an amount of data to return was specified (e.g. read(5)
, readline()
, readlines(10)
).
Writing
When writing, any new data written to the buffer is not immediately reflected in the database, but rather deferred until a flush()
operation is performed. This can be done explicitly by calling flush()
directly on the handle object, but is also done implicitly by multiple other methods, most notably close()
.
Memory Efficiency
The data in the buffer is retained until close()
so it is recommended to always remember to close GlyueFileHandle
objects once their data is no longer needed. This will free up system memory, and is incredibly important when working on larger files.
As a Field Mapping Value
Use the custom File
type to allow the integration engine to process a GlyueFileHandle
object as a valid value in a field mapping table (in this example, the file
variable is a GlyueFileHandle
object):
field | value | type |
someFieldName | file | File |
Viewing / Downloading files from the Run History page
Any GlyueFileHandle
objects that are historized or appear in a service request payload will be shown underneath as clickable download links:
Database GlyueFile Retention
GlyueFile
s in the database are related to an IntegrationRunHistory
and are subject to the corresponding IntegrationConfig
's run history payload storage settings, and will be deleted after the number of days specified. If turned off altogether, files are purged from the database at the end of the integration run and will not be downloadable from the Run History page.
Sub-integration behavior
A sub-integration’s config must have Store payloads in run history
turned on if it will return a new GlyueFileHandle
to its parent.
As part of a sub-integration, it may be desirable to output/return a GlyueFileHandle
to the parent. However, any Glyue files created during a sub-integration run will be subject to the child’s integration config. If Store payloads in run history
is turned off then the file in the database will be purged upon completion of the run, regardless of whether or not its handle object has been given to the parent and is still alive. A DoesNotExist
exception will be raised if the parent integration attempts to perform any operations that would interact with the file (now purged) in the database. If the file handle already has the data in its buffer, it may still be readable, however.
Last updated