Complete API documentation for Python OOUI.
ooui/
├── graph/ # Graph processing components
│ ├── __init__.py # parse_graph()
│ ├── base.py # Graph base class
│ ├── chart.py # GraphChart class
│ ├── indicator.py # GraphIndicator classes
│ ├── axis.py # Axis processing
│ ├── fields.py # Field operations
│ ├── processor.py # Data processing utilities
│ └── timerange.py # Time range handling
├── tree/ # Tree view components
│ ├── __init__.py # parse_tree()
│ └── base.py # Tree class
└── helpers/ # Utility modules
├── __init__.py # Common utilities
├── conditions.py # ConditionParser
├── domain.py # Domain class
├── aggregated.py # Aggregator class
├── dates.py # Date utilities
└── features.py # Feature detection
Parse a graph definition from XML string.
Parameters:
xml(str): XML string containing graph definition
Returns:
- Graph object (GraphChart, GraphIndicator, or GraphIndicatorField)
Raises:
ValueError: If graph type is invalid or unsupported
Example:
from ooui.graph import parse_graph
xml = '''
<graph type="line" string="Sales Chart">
<field name="date" type="date"/>
<field name="amount" type="float" operator="sum"/>
</graph>
'''
graph = parse_graph(xml)Base class for all graph types.
string: Graph title/labeltype: Graph type (line, bar, pie, indicator, indicatorField)fields: List of field names used in the graph
Process data for the graph.
Parameters:
values(list): List of data dictionariesfields(dict): Field definitionsoptions(dict, optional): Processing options
Returns:
- Processed data structure ready for visualization
Chart-type graphs (line, bar, pie).
x: X-axis configurationy: Y-axis configuration (list of axis objects)
Same as Graph base class plus chart-specific processing.
Example:
# Sample data processing
data = [
{'date': '2023-01-01', 'sales': 1000},
{'date': '2023-01-02', 'sales': 1200}
]
fields = {
'date': {'type': 'date'},
'sales': {'type': 'float'}
}
result = chart.process(data, fields)Single-value indicator graphs.
field: Main field configurationcompare_field: Optional comparison fieldprogressbar: Whether to display as a progress bar (boolean)show_percent: Whether to display the percentage value (boolean)suffix: Optional suffix to append to the value (e.g., '%', 'kW')color: Conditional color expressionicon: Conditional icon expressiontotal_domain: Domain for calculating the total value
Process indicator data and return formatted result.
Parameters:
value: The indicator valuetotal(optional): The total value for percentage calculation
Returns:
- Dictionary containing:
value: The indicator valuetotal: The total value (if provided)type: Graph type ('indicator')percent: Calculated percentage (if progressbar or show_percent is True)progressbar: True if progressbar attribute is setshowPercent: True if showPercent attribute is setsuffix: Value suffix (if set)color: Evaluated color (if color condition is set)icon: Evaluated icon (if icon condition is set)
Example:
# Basic indicator
xml = '''
<graph type="indicator" string="Total Sales">
<field name="total" type="float" operator="sum"/>
</graph>
'''
indicator = parse_graph(xml)
# Indicator with progress bar
xml = '''
<graph type="indicator" string="Completion" progressbar="1">
<field name="completed" type="integer" operator="sum"/>
</graph>
'''
indicator = parse_graph(xml)
result = indicator.process(75, 100)
# result: {'value': 75, 'total': 100, 'type': 'indicator', 'percent': 75.0, 'progressbar': True}
# Indicator with percentage display
xml = '''
<graph type="indicator" string="Success Rate" showPercent="1" suffix="%">
<field name="success" type="integer" operator="sum"/>
</graph>
'''
indicator = parse_graph(xml)
result = indicator.process(85, 100)
# result: {'value': 85, 'total': 100, 'type': 'indicator', 'percent': 85.0, 'suffix': '%', 'showPercent': True}Field-based indicators with multiple values.
Similar to GraphIndicator but handles multiple field indicators.
Parse a tree view definition from XML.
Parameters:
xml(str): XML string containing tree definition
Returns:
- Tree object
Example:
from ooui.tree import parse_tree
xml = '''
<tree string="Customer List" editable="top">
<field name="name"/>
<field name="email"/>
</tree>
'''
tree = parse_tree(xml)Represents a tree view configuration.
string: Tree title/labelinfinite: Whether tree supports infinite scrollingcolors: Color condition stringstatus: Status condition stringeditable: Edit mode (top, bottom, etc.)fields: List of field elementsfields_in_conditions: Dict of fields used in color/status conditions
Tree objects are primarily data containers. Field processing is handled by the parsing system.
Example:
# Access tree properties
print(tree.string) # "Customer List"
print(tree.editable) # "top"
print(len(tree.fields)) # 2
# Check conditional fields
if tree.colors:
conditional = tree.fields_in_conditions
print(conditional.get('colors', [])) # Fields used in color conditionsParse boolean values from string representations.
Parameters:
attribute: Value to parse (string, int, or bool)
Returns:
Truefor "1", "true" (case-insensitive)Falseotherwise
Example:
from ooui.helpers import parse_bool_attribute
print(parse_bool_attribute('1')) # True
print(parse_bool_attribute('True')) # True
print(parse_bool_attribute('0')) # FalseReplace HTML entities with Unicode characters.
Parameters:
text(str): Text containing HTML entities
Returns:
- Cleaned text string
Example:
from ooui.helpers import replace_entities
text = "Price > $100 & < $200"
clean = replace_entities(text)
print(clean) # "Price > $100 & < $200"Parse and evaluate conditional expressions.
ConditionParser(condition)Parameters:
condition(str): Condition string in format "result1:condition1;result2:condition2"
involved_fields: Set of field names used in conditionsraw_condition: Original condition string
Evaluate conditions against provided values.
Parameters:
values(dict): Field values to evaluate against
Returns:
- Result value if condition matches, None otherwise
Example:
from ooui.helpers import ConditionParser
parser = ConditionParser("red:amount < 100;green:amount >= 100")
print(parser.involved_fields) # {'amount'}
result = parser.eval({'amount': 50})
print(result) # "red"
result = parser.eval({'amount': 150})
print(result) # "green"Parse and evaluate domain expressions (query filters).
Domain(domain)Parameters:
domain(str): Domain expression string
Parse domain with optional variable substitution.
Parameters:
values(dict, optional): Variable values for substitution
Returns:
- Parsed domain structure
Example:
from ooui.helpers import Domain
# Simple domain
domain = Domain("[('active', '=', True)]")
result = domain.parse()
# Domain with variables
domain = Domain("[('user_id', '=', user)]")
result = domain.parse({'user': 42})Aggregate data with various operations.
Aggregator(rules)Parameters:
rules(dict): Aggregation rules mapping
Aggregate data according to rules.
Parameters:
data(list): List of data dictionariesgroup_by(str, optional): Field name to group by
Returns:
- Aggregated data structure
Example:
from ooui.helpers.aggregated import Aggregator
aggregator = Aggregator({
'total': {'operator': 'sum', 'field': 'amount'},
'count': {'operator': 'count', 'field': 'id'}
})
data = [
{'amount': 100, 'id': 1, 'category': 'A'},
{'amount': 200, 'id': 2, 'category': 'A'},
{'amount': 150, 'id': 3, 'category': 'B'}
]
result = aggregator.aggregate(data, group_by='category')
# Result: {'A': {'total': 300, 'count': 2}, 'B': {'total': 150, 'count': 1}}Apply aggregation operator to list of values.
Parameters:
values(list): Numeric valuesoperator(str): Operation ('sum', 'avg', 'max', 'min', 'count')
Returns:
- Aggregated result
Example:
from ooui.graph.fields import get_value_for_operator
values = [10, 20, 30, 40, 50]
print(get_value_for_operator(values, 'sum')) # 150
print(get_value_for_operator(values, 'avg')) # 30
print(get_value_for_operator(values, 'max')) # 50
print(get_value_for_operator(values, 'count')) # 5Represents a date range with start and end dates.
DateRange(start, end)Parameters:
start: Start date (string or datetime)end: End date (string or datetime)
start: Start datetime objectend: End datetime object
Get predefined date ranges.
Parameters:
period(str): Period identifier ('today', 'this_week', 'this_month', etc.)
Returns:
- DateRange object
Example:
from ooui.helpers.dates import get_date_range, DateRange
# Predefined ranges
this_month = get_date_range('this_month')
print(this_month.start)
print(this_month.end)
# Custom range
custom = DateRange('2023-01-01', '2023-12-31')ValueError: Invalid graph types, malformed conditionsAttributeError: Missing required attributesKeyError: Missing field referencesXMLSyntaxError: Malformed XML (from lxml)
try:
graph = parse_graph(xml_string)
result = graph.process(data, fields)
except ValueError as e:
print(f"Configuration error: {e}")
except Exception as e:
print(f"Processing error: {e}")Python OOUI supports both Python 2 and 3, so type annotations are not used in the source code. However, for modern development, expected types are:
# Function signatures (for reference)
def parse_graph(xml: str) -> Graph
def parse_tree(xml: str) -> Tree
def parse_bool_attribute(attribute: Union[str, int, bool]) -> bool
def replace_entities(text: str) -> str
class ConditionParser:
def __init__(self, condition: str) -> None
def eval(self, values: Dict[str, Any]) -> Optional[str]
class Domain:
def __init__(self, domain: str) -> None
def parse(self, values: Optional[Dict[str, Any]] = None) -> Any