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: str
, Enum
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: str
, Enum
Available element type variables. These element types are typically used by specific modes
(e.g. EXTRACT
, EXTRACT_ALL
and STREAMLIT
modes).
INPUT
:InputElement
type"INPUT"
OUTPUT
:OutputElement
Type"OUTPUT"
Env
¶
Bases: str
, Enum
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 in STREAMLIT mode. 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")
Keyword
¶
Bases: str
, Enum
Reserved keywords for the Streamlit app.
DATA
: Streamlit variable holding the data"_DATA_"
Mode
¶
Bases: str
, Enum
Available modes to run OneCode projects:
CONSOLE
: return the initial element class. Typically used in the interactive Python console. It is the defaultProject()
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 inProject().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"
STREAMLIT
: generate the Streamlit app code and run it. Typically used through theonecode-start
CLI."_build_streamlit"
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
# ...