Attribute output

SchemaCommandLine (SCL) can print selected attributes of the constructed application object. The schema-level print_attribute setting enables --print-attribute. A target_class is required, and print_attribute is reserved as an injected SCL control field.

Discover public properties

from data_schemer.schema_command_line import SchemaCommandLine

class Summary:
    def __init__(self, values):
        self.values = values

    @property
    def mean(self):
        return sum(self.values) / len(self.values)

    @property
    def maximum(self):
        return max(self.values)

schema = {
    "variables": {"values": {}},
    "print_attribute": True,
}

scl = SchemaCommandLine(
    schema, target_class=Summary,
    argv=["--values", "[1, 2, 3]", "--print-attribute", "mean"],
)
mean: 2.0

Automatic discovery exposes public @property names, including inherited properties, including functools.cached_property descriptors. It does not discover every instance attribute. The requested attribute is read after application construction and _operations().

Select external names

Use a configuration dictionary for explicit choices or aliases:

schema["print_attribute"] = {
    "choices": ["average", "maximum"],
    "code_alias": {"average": "mean"},
}
scl = SchemaCommandLine(
    schema, target_class=Summary,
    argv=["--values", "[1, 2, 3]", "--print-attribute", "average"],
)
average: 2.0

The command-line spelling is external; mean is the internal attribute name. Schema field code_alias mappings also participate in attribute-name mapping. The explicit output mapping must not overlap their external names or internal targets. Attribute aliases must be one-to-one.

When choices is a list, it controls validation and completion. Manual choices can name attributes that are not @property descriptors, provided they exist on the constructed object.

Automatic exclusions

schema["print_attribute"] = {"exclude": ["maximum"]}

Exclusions apply during automatic discovery only when the configuration has no choices key. An excluded internal name or its external alias removes the property. An explicit choices: None selects automatic discovery but suppresses exclusions; key presence is significant.

Output representation

Default attribute output uses DataCanon YAML interchange. A supported value that YAML cannot represent faithfully uses a $ Shorthand airlock. Each requested attribute is printed separately under its external name.

Set omit_key: True to print just the value, still using DataCanon (DC) YAML interchange. For example:

schema["print_attribute"] = {"choices": ["mean"], "omit_key": True}

This output path converts the application attribute using DC’s conventional conversion rules. The original input DataCanon Instance (DCI) is not changed.

Application reports

SCL always uses DC YAML interchange for attribute output. An application that wants rounded tables, labels, or a specialized report should format that output in its own code, for example in _operations(). The former precision_from and array_style_from settings are rejected with migration guidance.

The behavioral reference describes output-configuration inheritance.