Skip to content

Output Elements API

Available output elements for OneCode projects:

file_output

def file_output(
    key: str,
    value: str,
    label: Optional[str] = None,
    tags: Optional[List[str]] = None,
    make_path: bool = False
)

Basic information about the file, such as size and file path.

Parameters:

Name Type Description Default
key str

ID of the element. It must be unique as it is the key used to story data in Project(), otherwise it will lead to conflicts at runtime in execution mode. The key will be transformed into snake case and slugified to avoid any special character or whitespace. Note that an ID cannot start with _. Try to choose a key that is meaningful for your context (see examples projects).

required
value str

Path to the output file. Unless absolute, a path is relative to the outputs folder of the flow currently running.

required
label Optional[str]

Typically to be used for display purpose only. If not defined, it will default to the key.

None
tags Optional[List[str]]

Optional meta-data information about the expected file. This information is only used when the JSON output attributes are written to the output manifest.

None
make_path bool

True to create the directory structure of the given file path.

False
**kwargs Any

Extra user meta-data to attach to the element. Argument names cannot overwrite existing attributes or methods name such as _validate, _value, etc.

{}

Raises:

Type Description
ValueError

if the key is empty or starts with _.

AttributeError

if one the kwargs conflicts with an existing attribute or method.

Example

from onecode import file_output, Mode, Project

Project().mode = Mode.EXECUTE
Project().current_flow = 'test'

file = file_output(
    key="FileOutput",
    value="/path/to/file.txt",
    label="My FileOutput",
    tags=['TXT'],
    make_path=True
)

with open(file, 'w') as f:
    f.write('Hello OneCode!')

print(file)
Output
# create /path/to folders
"/path/to/file.txt"