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 |
required |
value |
str
|
Path to the output file. Unless absolute, a path is relative to the |
required |
label |
Optional[str]
|
Typically to be used for display purpose only. If not defined, it
will default to the |
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 |
{}
|
Raises:
Type | Description |
---|---|
ValueError
|
if the |
AttributeError
|
if one the |
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)
# create /path/to folders
"/path/to/file.txt"