Skip to content

Enumerations

How to use Enums

Enums can be used in functions as Python object (int, float or strings) or as OneCode attribute.

For example

from oncode import file_input, FileFilter

widget = file_input(
    key="FileInput",
    value="/path/to/file1.txt",
    types=[FileFilter.IMAGE]
)

is equivalent to

from oncode import file_input, FileFilter

widget = file_input(
    key="FileInput",
    value="/path/to/file1.txt",
    types=[("Image", ".jpg .png .jpeg")]
)

ConfigOption

Bases: StrEnum

Available options to control the configuration of the project.

  • FLUSH_STDOUT: to force flushing the logger "FLUSH_STDOUT": False
  • LOGGER_COLOR: to color the logs by default when resetting the logger "LOGGER_COLOR": True
  • LOGGER_TIMESTAMP: to timestamp the logs "LOGGER_TIMESTAMP": True

ElementType

Bases: StrEnum

Available element type variables. These element types are typically used by specific modes (e.g. EXTRACT and EXTRACT_ALL modes).

  • INPUT: InputElement type "INPUT"
  • OUTPUT: OutputElement Type "OUTPUT"

Env

Bases: StrEnum

Available environment variables for OneCode projects:

  • ONECODE_PROJECT_DATA: use this variable to overwrite default data location "ONECODE_PROJECT_DATA"
  • ONECODE_CONFIG_FILE: name of the file containing OneCode project configurations ".onecode.json"
  • ONECODE_DO_TYPECHECK: set to 1 to force runtime type-checking with Pydantic "ONECODE_DO_TYPECHECK"
  • ONECODE_LOGGER_NAME: base logger name to avoid logging conflict with other loggers |OneCode|

FileFilter

Bases: tuple

Available file filters, typically used by FileInput Element. It allows to filter file selection within the Open File Dialog. File filters are a Tuple made of 2 parts: (name of the filter, file extensions separated by whitespaces).

  • CSV ("CSV", ".csv")
  • PYTHON ("Python", ".py")
  • IMAGE ("Image", ".jpg .png .jpeg")
  • ZIP ("ZIP", ".zip .gz .tar.gz .7z")

Mode

Bases: StrEnum

Available modes to run OneCode projects:

  • CONSOLE: return the initial element class. Typically used in the interactive Python console. It is the default Project() mode. "_console"
  • EXECUTE: run the project with the default provided values. Typically used for running the Python scripts from the command line: python main.py "_execute"
  • LOAD_THEN_EXECUTE: read parameters previously loaded in Project().data. Typically used for running the Python scripts from the command line: python main.py params.json "_load_then_execute"
  • EXTRACT: extract parameters and their default value to JSON. It may be used either through regular Python scripts or the CLI. "_extract"
  • EXTRACT_ALL: extract parameters, their default value and all their attributes (kind, name, etc.) to JSON. It may be used either through regular Python scripts or the CLI. "_extract_all"
  • BUILD_GUI: write the UI file (JSON format) readable by OneCode Cloud to build the graphical user interface "_build_gui"

These modes correspond to the function names of the Input/Output Element objects (e.g. InputElement._execute()). Therefore you can easily extend Input/Output Element with new modes by simply implement new methods in a derived class and set the mode to it.

Example

from onecode import InputElement, process_call_graph, Project


class MyElement(InputElement):
    # ... inherit InputElement methods as needed

    def _my_new_mode(self):
        # implement the gist of your new mode here
        # ...


def do_my_new_mode(onecode_project_path: str):
    Project().mode = '_my_new_mode'
    result = process_call_graph(onecode_project_path)

    # do something with result
    # ...